0

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

1 Answer 1

2

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"
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.