I created a Content folder in wwwroot, because I read that client side things like stylesheets and scripts should be added there in the doc, but when I add to a View I have and build the project it does not find the files. What is the correct way to do this ?
<link href="~/content/style.css" rel="stylesheet" />
I am pretty sure the wwwroot is added to project.json correctly.
"webroot": "wwwroot"
The path of the wwwroot folder is accessed using the interfaces IHostingEnvironment (. Net Core 2.0) and IWebHostEnvironment (. Net Core 3.0) in ASP.Net Core.
UseDefaultFiles is a URL rewriter that doesn't serve the file. With UseDefaultFiles , requests to a folder in wwwroot search for: default. htm.
The UseStaticFiles is an extension method included in the StaticFiles middleware so that we can easily configure it. Now, open the browser and send http request http://localhost:<port>/default.html which will display default. html as a response as shown below. Serving HTML File.
Static files like JavaScript files, images, CSS files that we have on the file system are the assets that ASP.NET Core application can serve directly to clients. Static files are typically located in the web root (wwwroot) folder.
You need to enable ASP.NET Core static files handling in your Startup:
public void Configure(IApplicationBuilder application)
{
// Add static files to the request pipeline.
application.UseStaticFiles();
// Add MVC to the request pipeline.
application.UseMvc();
}
You also need to add this to your csproj unless you are using the Microsoft.AspNetCore.All
package:
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0" />
You also need to add this to your project.json:
"dependencies": {
"Microsoft.AspNetCore.StaticFiles": "1.0.0"
// ...Omitted
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With