Import namespaces automatically into all cshtml files in App_Code folder - c#

For some reason for all my .cshtml files in App_Code folder I have to explicitly import namespaces with #using Namespace directive.
However, I do not have to do that for any .cshtml view that is located in the Views folder because I have added the needed namespaces to the web.config file in the Views folder.
So, is there a similar way to add the desired namespaces so they will be automtically imported into the files residing in App_Code folder as well?
EDIT: What's in App_Code folders are not views, but supporting .cshtml files containing primarily #helpers.

Related

Renaming default folders in Blazor project

I want to rename the Shared folder in my Blazor Server project to Components, how can I do that properly? It seems like namespaces are based on folder names but there must be a way right?
You can just rename the Folder to Components. That does indeed change the namespace, edit the _Imports.razor file like this:
#*#using MyApp.Shared*# -- remove this line
#using MyApp.Components

asp.net core IHtmlLocalizer not work

I write #inject IHtmlLocalizer Localizer in _Layout.cshtml, but it isResourceNotFound = true? why?
The structure of the Resources folder might not follow the structure of the Views folder. By convention, _Layout.cshtml is located in the Views/Shared folder. Therefore, your Resources folder should reflect that: resource files for the layout should be in Resources/Views/Shared folder.

What is wwwroot in asp.net vnext

I create new asp.net mvc project in visual studio 2015.The project has a wwwroot file.What is this?
Quoting the official website:
The wwwroot folder is new in ASP.NET 5.0. All of the static files in
your project go into this folder. These are assets that the app will
serve directly to clients, including HTML files, CSS files, image
files, and JavaScript files. The wwwroot folder is the root of your
web site. That is, http://some.hostname/ points to wwwroot, all URLs for
static content are relative to the wwwroot folder.
Code files should be placed outside of wwwroot. That includes all of your C# files and Razor files. > Having a wwwroot folder keeps a clean separation between code files and static files.
Source
It's worth mentioning that the term wwwroot itself is certainly not new and it's actually a convention used across many platforms (including J2EE applications and IIS itself with its c:\inetpub\wwwroot directory).
Similar conventions in the Unix/Linux world are htdocs, public_html and www.
The wwwroot folder is new in ASP.NET 5 to store all of the static files in your project. Any files including HTML files, CSS files, image files, and JavaScript files which are sent to the user's browser should be stored inside this folder.
Code files should be placed outside of wwwroot, including C# files and Razor views. Having a wwwroot folder keeps a clean separation between code files and static files. It brings clarity to the items that will be sent to the server and the items that should remain on the dev machine. If you look at the screenshot, wwwroot folder has css and lib sub folders. Css folder is a place to keep your custom css files, while lib folder is used by Bower package manager. The lib folder contains the packages downloaded by Bower and can contain css, js and images.
The screenshot shows that lib folder has a bootstrap package folder. If you expand it, you will find css, js, as well all other assets related to the bootstrap package.
In MVC4, we used the content folder to keep style sheets as well as scripts folder for referenced scripts. These folders are gone now, so it's important to understand that there is no single folder for style sheets or scripts. They could be in any of the folders within wwwroot.
It's interesting to note that if you wish to reference the css, js, or img files in your razor views, using the ~ keyword ensures direct path to the wwwroot folder. So suppose you wanted to reference site.css in your view, you can access it using the <link rel="stylesheet" href="~/css/site.css" /> syntax.
You can see that the ~ keyword points to the wwwroot folder.

Alternatives to ItemGroup/Compile and App_Code for running/debugging C# in Visual Studio

In Web Applications, we add .cs files to the .csproj's Project/ItemGroup/Compile.Include attribute. This inputs the file into the build, which compiles it into a bin folder assembly.
In Websites, we add .cs files to the App_Code folder. The files compiles at run time.
Not to add a .cs file to either ItemGroup/Compile.Include or App_Code means that the compiler will not run the code.
Are there any other ways to make a .cs file run?

How to put .cs file in app_code and its ascx file out of app_code folder?

In a ASP.net website project how to link cs file in app_code with ascx file of a UserControl ?
Rather than putting into app_code you should put it into app_theme folder.
Here is a MSDN link for the same.

Categories