8

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"
Dave Demirkhanyan
  • 570
  • 1
  • 5
  • 22

2 Answers2

13

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();
}

Visual Studio 2017 (csproj)

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" />

Visual Studio 2015 (xproj + project.json)

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

"dependencies": {
    "Microsoft.AspNetCore.StaticFiles": "1.0.0"
    // ...Omitted
}
Muhammad Rehan Saeed
  • 35,627
  • 39
  • 202
  • 311
0

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.

Amit
  • 45,440
  • 9
  • 78
  • 110