Stas Petrov Stas Petrov - 1 month ago 8
ASP.NET (C#) Question

Css in different folder

I am trying to make something like "templates system" it might allow user to change site template. In admin panel for example.

My current files structure


In default controller (home) i check current template name and show right view

private ViewResult TemplateView(string viewName)
return View($"~/Views/Templates/{GlobalSettings.CurrentTemplate}/{viewName}.cshtml");

And some template View (

<link rel="stylesheet" href="~/Views/Templates/DefaultTemplate/css/style.css" type="text/css" />

But I dont know how write correct path to my css\js\ images in right template forder.

I have tried



But in result HTML it is like
so i got 404 (not found)

I have also tried this


In this case i got 404 too.

So, can anybody help me? How to write correct URL to CSS, images, hs etc ?

Div Div

The web.config file in the /Views folder restricts all access to files in the folder by default:

Add code to your web.config file:

    <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>

Note: It's not good practice to store css files inside view folder.