Stas Petrov Stas Petrov - 1 year ago 145
ASP.NET (C#) Question

ASP.NET MVC 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 exmaple.

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 (Index.cshtml)

<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
Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download