2

By default, static assets in a .NET MVC application live in two different directories, /Content and /Scripts. Is there any way to configure Visual Studio's server to look for static assets in other directories?

For instance, if I load /css/main.css, I need it to load ~/Assets/css/main.css. Do I need to set up a route?

2
  • Assets live there because that's where they are put. No other reason. You can put them anywhere you want. There is no configuration for this, just change the locations that you reference. If you're using bundling, you'll have to change the bundle locations though. Commented Apr 21, 2014 at 16:47
  • Poorly-worded question. I'm looking for how to map requests for static assets to the non-default locations. Commented Apr 21, 2014 at 17:04

1 Answer 1

1

Those two folders are just the defaults, there's nothing hard-wired in MVC to look for those directories. Even if you use something like Url.Content, you still have to specify the Content folder in the path, if that's what you're looking for, i.e. Url.Content("~/Context/site.css"). The bundler, also, requires you specific the complete application-relative path.

You can change the folders to whatever you like, as long as you specify the references appropriately as well.

The only thing that is sort of hard-wired is nuget packages that have associated CSS and JS files. That has more to do with the developers, though. Since Content and Scripts are the default directories, nuget package developers set these folders as the ones to dump their associated files into. So, if you move everything to a new folder like Assets, the next nuget package you install, will most likely recreate the Content and Scripts folders and dump their files there. Now, there's nothing preventing you from then manually moving those files into your preferred location, but it's going to get old quick as you deal with package updates and such.

I've found it easier to just get over it and use the default directories, but like I said, there's absolutely nothing hard-wired in the system to force you to do that. Just understand, that you'll have to manually rearrange things from time to time to keep it sorted the way you like.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the clarification. I've re-worded my question to better explain that I'm looking for mapping the routes served by Visual Studio to the non-default file locations.

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.