What is wwwroot in asp.net vnext - c#

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.

Related

How do I overwrite the default "site.css" that is generated -by something- in dotnet core in the account management mvc section

I have created a scaffolded SPA application where a default UI MVC project was created. I have managed to "scaffold" this where I now have all the .cshtml for account management files locally. I see a "site.css" file loaded from some location somewhere. I want to copy the contents of this file, place it locally -so I can edit it-.
I can simply remove the reference to site.css and add my own *.css reference. But it seems odd that a site.css file is being generated from somewhere and it isn't obvious where it comes from.
The only information I can find on this strange behaviour is:
Where is the site.css file located for Identity?
"you can override those by simply creating files in the same location in your project"
I have tried creating site.css in the "same location"(where is the same location?) but it didn't work. It still loads site.css
[project root]/wwwroot/css/site.css
All public facing files are in the wwwroot folder. So that is where your css, images, javascript, etc. files will go.
Note: "wwwroot" folder is near the top in the Solution Explorer, it doesn't follow the ABC ordering.

IIS deployment cannot contains files for wwwroot folder in asp.net core 2.2 razor pages

I have subfolders of JS and CSS in my wwwroot folder of asp.net core razor page application. Application works fine in local environment, but while deployment of the project on IIS, the wwwroot folder does not contain any subfolders or files in it.
Even if I manually upload the folders and files to wwwroot folder, it doesn't work and it does not load the JS and CSS files in the browser.
Note that I do not have "Environment" tags in my application.
Try to edit the .csproj file of your asp.net core project:
Remove all the ItemGroup tags and their contents then add this
<ItemGroup>
<None Include="wwwroot\*" />
</ItemGroup>
You could refer this link for more detail:
Visual Studio publish profiles for ASP.NET Core app deployment
There are two ways of setting the js/css path
Absolute Path
Relative Path
Absolute Path is, you have to give proper path in web server .
http://<website name>/css/site.css
Relative Path is, you can give file page relative to current page.
let say your page is from http://<website name>/index.html
relative path will be ./css/site.css
Better you try to access js or css file from browser. may be these folders do not have right permission to access.
if you open Dev Tool, you can see the error in Network tab or console. Base on HTTP code, you can decide what has happened
In my scenario I was adding MVC to my .Net 5 API
The solution was to add
app.UseStaticFiles();
to the Startup.cs

Why can't I see the Controllers folder within my deployed MVC web app directory?

I have recently purchased a shared web hosting package, provided by GoDaddy, and deployed my own MVC web application to it.
My problem is that, when on the control panel (Plesk) provided by the host, I can't find the Controllers folder that contains all the behind code.
Is there a reason for this folder being hidden?
I'm guessing it's because the files within this folder are being used by the server all the time and can't be accessed/changed incase it f--ks everything up... But I am not sure about it because I am quite new to web hosting.
Thanks for any assistance in advance.
All your cs files including controllers will be compiled into DLL files. Please open "bin" directory to find all your DLLs.
When you deploy, u ll not get controller, because it contains c# code which changed to dll available inside bin folder.
Not Only Controller, the other folders which are having C# code like "App_Start"...and etc...will be changed to dll and will be available inside bin folder.
In the case of Model/s, if you are using Entity framework, then, the .edmx file will be available inside the Model folder.
All your Business logics including controllers, models and core etc are converted to dll and by Assembly name dll is created in bin (released or debug folder)

Where do I put .less files in my Visual Studio Web Application?

I want to include a .less file in my Visual Studio Web Forms Application. I am running on the default template for VS 2015. Just wondering which folder to put the .less file in, and where I need to reference it (if at all). Currently all .css files are in the "Content" folder - should I just add it in there?
Please let me know if that's not enough information to go on.
Thanks!
for me and my team projects we use "Content" host sub folder for .less file and compiled CSS. when we compile .less file to CSS using gulp or grunt we output file to "CSS" or "Style" folder. you can create Grunt or gulp task to compiled file to CSS or style folder. this is npm package to compile less to CSS https://www.npmjs.com/package/gulp-less
>Content
---->/LESS
---->/CSS/Style
You will only need .less files when building your CSS. I would suggest a folder you don't plan on deploying to your website. You will only need to include the CSS files that are generated in your Content folder.
I've organized my directories as /Content for CSS and /src for any source files. When I publish to the website I only include the /Content folder. All references should be to the CSS file.
Root
/Content (CSS)
/src (less)

ASPX: Get path of cs file

How can I get the path of a cs file in aspx?
Here's the issue: I've created a property class in a property.cs file which is used in an EPiServer admin module. Server.MapPath() will hence return the path of the executing file, which is in a totally different place than my code. I need to get the path of the property.cs file (from inside the property.cs file) in order to dynamically set some relative paths to css and js files. How can this be done?
I hence want to be able to include .js and .css files in this cs file, all files located in the same directory, but the cs file is accessed from the EPiServer UI.
I would highly recommend not doing what you are trying to do. You'll be constructing a brittle dependency on files that should not even by deployed with your project.
If you have web classes that rely on resources like javascript and css, you should use the ClientScriptManager (or ScriptManager for ajax apps) to register the script files onto the page, and the scripts and css should be deployed into their own regular web directory.
If deployment location is a problem, and you're creating some kind of reusable, redistributable module, then I would recommend that you embed the .js and .css files as WebResources in your assembly, and use the script manager to register the scripts to the page that way, with ClientScriptManager.RegisterScriptResource().
I think you should go with including your CSS, JS and other static files as embedded resources.
That will include the files inside the DLL, which makes deployment easier. You can then set up a HTTP handler which will serve you the contents of the embedded files - or use the aforementioned RegisterScriptResource() method.
By embedded the files you don't have to know any file paths.
ASP.NET is compiled, you should never need to read settings from source files at runtime, you should read from configuration files (*.config), if they need to be dynamic, these too can be injected during the page lifecycle via a variety of methods.

Categories