Reputation: 570
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"
Upvotes: 8
Views: 5916
Reputation: 38437
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
}
Upvotes: 13
Reputation: 46323
The tilde ("~"
) symbol translates to base url, but that happens in server code, through server controls or other server side url manipulation functions.
For client side URL, remove the tilde.
Upvotes: 0