Reputation: 24978
Is the Content folder special to the underlying framework of MVC? I can't find any reference to it in routing code or configuration.
I'm just wondering if static content can be handled in different ways.
On a related note, stackoverflow's script and css content seems to be retrieved by version number in the querystring:
<link href="/Content/all.min.css?v=2516" rel="stylesheet" type="text/css" />
Care to speculate how this might work and why this would be important?
Upvotes: 23
Views: 12822
Reputation: 2076
No magic, the System.Web.Routing.RouteCollection class has a property RouteExistingFiles which controls the behavior.
The default is false, which means ASP Routing should not route the URL, but just return the default content. In this case the "/Content/all.min.css?v=251" skips the MVC routing rules entirely.
if you want to add a routing rule for the content folder, you need to add the rule, and set RouteExistingFiles to true.
Upvotes: 19
Reputation: 26976
Just to add to the other comments about this - the way the routing system works is as follows:
A request comes in, and is directed to the routing engine, which then looks through the route table for a match - in the order they are registered (which is why you should put more specific routes before more general routes).
If no match is found, the routing engine passes the request on to IIS to handle normally - this is also how you can intermix ASP.NET webforms and MVC in the same application.
Upvotes: 3
Reputation: 1064144
No, the Content folder is not sacred. Use it as you like.
Re the version - that is a common trick to help with versioning if you have http-header based caching enabled; otherwise you can't guarantee that all clients are using the updated files. You'll see a lot of "foo_v4.js" etc on the web ;-p
Upvotes: 5
Reputation: 1039498
It has no special meaning. It is just an arbitratry name. If you use the wizard of ASP.NET MVC RC you will find that it is referenced inside your master page (Site.master):
<link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
As to all.min.css used in SO, it could be a custom handler that is executed on the server to retrieve a compressed style sheet by version.
Upvotes: 1
Reputation: 35496
I use the same technique on some of my sites. I use it to avoid caching - if you do not specify a different URL for the different builds, clients may have cached the old one.
Upvotes: 4