I am running ReGitLint for a Blazor project with a .editorconfig file at the root of the application.
When I run dotnet regitlint, it removes using statements that are not unused in .razor files.
For example
#using B2B.Web.Assets
#using B2B.Web.Components // this line is removed
#using Blazored.LocalStorage
#inject ILocalStorageService localStorage
#inject IStringLocalizer<Resource> localizer
<PageTitle>Index</PageTitle>
<AuthorizeView>
<Authorized>
...
</Authorized>
<NotAuthorized>
<Login />
</NotAuthorized>
</AuthorizeView>
The Login component is located inside Components folder and the line #using B2B.Web.Components is removed when running dotnet regitlint
My .editorconfig file contains the following
root = true
[*.{cs,razor}]
insert_final_newline = true
csharp_place_attribute_on_same_line = false
indent_style = space
indent_size = 4
[*.razor.cs]
dotnet_diagnostic.IDE0051.severity = none
dotnet_diagnostic.IDE0052.severity = none
[*.chtml.cs]
dotnet_diagnostic.IDE0051.severity = none
dotnet_diagnostic.IDE0052.severity = none
I have tried a lot of other things in this file.
Is there a way to disable unnecessary using directives in .editorconfig for razor files? Or any other solution to fix this problem.
Related
I am trying to publish our website. It works fine on debug and release but publish gives me this error. We are using ASP .NET 4.0. I am using Visual Study 2013 for this project.
Error:
CS0103: The name 'Bundles' does not exist in the current context
Line 28: <meta name="viewport" content="width=device-width, initial-scale=1" />
Line 29: <%--<meta name="google-translate-customization" content="78033ccfddd8ecc6-eef53fe980f2236d-g873f5a559b682a69-a" />--%>
Line 30: <%=Bundles.RenderStylesheets()%>
Line 31:
Line 32: <script>
Web Config:
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
Here is my config:
using Cassette;
using Cassette.Scripts;
using Cassette.Stylesheets;
using Cassette.BundleProcessing;
//using System.Web.Optimization;
namespace StudyXWebsite
{
/// <summary>
/// Configures the Cassette asset bundles for the web application.
/// </summary>
public class CassetteBundleConfiguration : IConfiguration<BundleCollection>
{
public void Configure(BundleCollection bundles)
{
// TODO: Configure your bundles here...
// Please read http://getcassette.net/documentation/configuration
// This default configuration treats each file as a separate 'bundle'.
// In production the content will be minified, but the files are not combined.
// So you probably want to tweak these defaults!
//bundles.AddPerIndividualFile<StylesheetBundle>("Content");
//bundles.AddPerIndividualFile<ScriptBundle>("Scripts");
bundles.Add<StylesheetBundle>("~/Styles/AllStyles.css");
bundles.Add<ScriptBundle>("~/Scripts/GGS.js");
bundles.Add<ScriptBundle>("~/Scripts/track.js");
// To combine files, try something like this instead:
// bundles.Add<StylesheetBundle>("Content");
// In production mode, all of ~/Content will be combined into a single bundle.
// If you want a bundle per folder, try this:
// bundles.AddPerSubDirectory<ScriptBundle>("Scripts");
// Each immediate sub-directory of ~/Scripts will be combined into its own bundle.
// This is useful when there are lots of scripts for different areas of the website.
}
}
}
Bin folder
I am trying to use DropzoneJS to upload multiple photos to a webapplication.
The Upload view contains following
<div class="jumbotron">
<form action="/Upload"
class="dropzone"
id="dropzoneJsForm"
style="background-color:#00BFFF"></form>
</div>
And the Upload controller contains this
[HttpPost]
public async Task<IActionResult> Upload(IFormFile file, IHostingEnvironment _environment)
{
var uploads = Path.Combine(_environment.WebRootPath, "uploads");
if (file.Length > 0)
{
using (var fileStream = new FileStream(Path.Combine(uploads, file.FileName), FileMode.Create))
{
await file.CopyToAsync(fileStream);
}
}
return RedirectToAction("Index");
}
When I run the application in debug mode and add files I see the progressbar and the checkmark indicating success. But no files has been uploaded in the upload folder in wwwroot.
I have app.UseStaticFiles() in the Configure method.
Target framework: .Net Core 2.0
I am using Visual Studio 2017 Professional latest version
<webconfig>
<system.web>
<httpRuntime maxRequestLength="15360" requestLengthDiskThreshold="15360"/>
</system.web>
'consider using fileupload='multiple' attribute on control
I found the mistake. A stupid beginner mistake. When I changed the name of the controller method to Index it worked.
I'm going to start a website which I know is going to be presented in multiple languages. However, for the first version we're only going to need the English version. Once the features are all working, we'll add the other languages.
Unfortunately since there are not enough enough features baked into Asp.Net Core, we have to use the Asp.Net MVC 5 for the website. My question has 2 parts:
Right now, which practice is considered the best approach for this? Using resource files and loading them in razor pages? Using a framework? Can we use the new localization and globalization features of Asp.Net MVC 6 somehow? Or is there a better alternative? I personally hate using the resource files. It adds too much clutter to the code.
Would you suggest just using plane text for now and then adding the Internationalization features to the website or start now and only add the translations?
I would use resource files, seems to be the easiest solution. You can also use a Database resource provider, so you have less clutter.
If you start with plain text, it will get more complicated and cumbersome to add the translations later. So I would not do that.
We use Smart internationalization for ASP.NET.
Features
Localize everything: HTML, Razor, C#, VB, JavaScript, .NET attributes
and data annotations, ...;
SEO-friendly: language selection varies the URL, and Content-Language is set appropriately;
Automatic: no URL/routing changes required in the app;
High performance, minimal overhead and minimal heap allocations; Unit testing support;
Smart: knows when to hold them, fold them, walk away, or run, based on i18n best practices.
How I use i18n in the project step by step:
Add the I18N nuget package to your MVC project.
in Web.config:
Add a folder named "locale" to the root of your site. Create a subfolder for each culture you wish to support. For example, /locale/fr/.
copy i18n.PostBuild.exe into locale folder
Right click on tne project name --> Properties --> Build Events:
in Post-build event command line:
"$(TargetDir)i18n.PostBuild.exe" "$(ProjectDir)\web.config"
In views use [[[some text]]] to translate it later
Build the project
Refresh Solution Explorer and push Show All Files
Include all files in "locale" folder into the project
Provide translation of the words in locale\fr\messages.po
In Global.aspx add :
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
//other app start code
UrlLocalizer.UrlLocalizationScheme = UrlLocalizationScheme.Void;
}
}
Create DefaultController :
public class DefaultController : Controller
{
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
base.OnActionExecuting(filterContext);
if (Session["currentLanguage"] == null)
{
Session["currentLanguage"] = "en";
}
}
}
In HomeController add inheritance of DefaultController and SwitchLanguage(string lang):
public class HomeController : DefaultController
{
public HomeController() : base()
{
[AllowAnonymous]
public async Task<ActionResult> SwitchLanguage(string lang)
{
LocalizedApplication.Current.DefaultLanguage = lang;
Session["currentLanguage"] = lang;
return Redirect(Request.UrlReferrer.PathAndQuery);
}
}
}
In navigation bar View (_LoginPartial.cshtml in my case) add links to switch between languages:
#if (Session["currentLanguage"].ToString() == "fr")
{
<li class="navItem">#Html.ActionLink("EN", "SwitchLanguage", "Home", new { lang = "en", area = "" }, null)</li>
}
else
{
<li class="navItem">#Html.ActionLink("FR", "SwitchLanguage", "Home", new { lang = "fr", area = "" }, null)</li>
}
Build project, Start in Browser and enjoy!!!
see some help in:
https://www.codeday.top/2017/09/19/42409.html
I'm trying to change the $menu_icon variable in CMSPageController without editing core files (IE: the icon next to menu item "Pages" in the CMS). I went on a limb and tried the following:
1: Define an extension to CMSPageController in _config.yml
CMSPageController:
extensions:
- ChangeMenuIcon
2: Define class and extend from CMSPageControllerExtension in mysite
class ChangeMenuIcon extends CMSPageControllerExtension {
private static $menu_icon = 'framework/admin/images/menu-icons/16x16/information.png';
}
This results in a 500 error. Is this actually the correct way to overwrite an existing (core) class property?
Faloude, since it's a private static you could try setting it directly in the config.yml rather than applying an extension.
CMSPagesController:
menu_icon: 'framework/admin/images/menu-icons/16x16/information.png';
I'm using MVC4 c#. I'm trying to load images that I need to show on a page dynamically by reading the content of the image folder and doing a foreach loop. I'm not sure how to read the content of the folder which is called ImageFiles which is located in the project and not the c:\ of the server. This is what I used and it works on my local computer but when I use ../../filename/filename/ImageFiles as the path it does not work. Can anyone help?
string filePath = #"../../Content/EventFiles/ImageFiles";
DirectoryInfo directory = new DirectoryInfo(filePath);
#foreach (FileInfo file in directory.GetFiles())
{
<\a href="../../Content/EventFiles/ImageFiles/#file.Name">
<\img src="/Content/EventFiles/ImageFiles/#file.Name" />
<\/a>
}
You are not referencing the filePath correctly.
Try this one on your View..
#{DirectoryInfo dir = new DirectoryInfo(Server.MapPath(Url.Content("~/Content/EventFiles/ImageFiles")));}
#foreach (var file in dir.GetFiles())
{
<img src="#Url.Content("~/Content/EventFiles/ImageFiles/" + file.Name)" />
}
Answer is Server.MapPath(). For desktop applications DirectoryInfo() works but for a web application I had to use Server.MapPath().
Thanks