blue piranha
blue piranha

Reputation: 3874

Unable to access local css file

Local css file called site.css is stored in Content folder in .net core project

Tried the following in layout

 <link rel="stylesheet" href="@Url.Content("~/Content/site.css")" />

as well as

 <link rel="stylesheet" href="~/Content/site.css" />

but didn't work.

In startup I have app.UseStaticFiles();

Is there anything I am missing? I am unable to access the css in the browser. Gives error in dev tools.

Thank you

Upvotes: 0

Views: 221

Answers (1)

Ivvan
Ivvan

Reputation: 730

UseStaticFiles() only serves content from wwwroot folder. It should works, if you move your css file to wwwroot/Content/.

If you want to serve static content from Content folder, you should apply config like below:

app.UseStaticFiles(new StaticFileOptions
{
    FileProvider = new PhysicalFileProvider(
        Path.Combine(Directory.GetCurrentDirectory(), "Content")),
    RequestPath = "/Content"
});

Upvotes: 2

Related Questions