CSS files not found in ASP.NET 5

I created the Content folder in wwwroot because I read that client-side elements such as stylesheets and scripts are added to the dock, but when I add to the View I have and create the project, it does not find the files. What is the right way to do this?

<link href="~/content/style.css" rel="stylesheet" /> 

I am sure wwwroot is correctly added to project.json.

 "webroot": "wwwroot" 
+7
c # asp.net-core asp.net-core-mvc
source share
2 answers

You need to enable processing of static ASP.NET Core files 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(); } 

Visual Studio 2017 csproj)

You also need to add this to your csproj if you are not using the Microsoft.AspNetCore.All package:

 <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0" /> 

Visual Studio 2015 (xproj + project.json)

You also need to add this to your project. json:

 "dependencies": { "Microsoft.AspNetCore.StaticFiles": "1.0.0" // ...Omitted } 
+10
source share

The tilde character ( "~" ) is converted to the base url, but this happens in the server code, through server controls or other server-side URL manipulation functions.

For the client-side URL, remove the tilde.

0
source share

All Articles