tags:

views:

996

answers:

5

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?

+3  A: 

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.

Mark S. Rasmussen
Good observation, I know that must be the reasoning.
BC
I use mysite.css?v=xx all the time - huge pain in the ass otherwise to tell your client to clear their cache or shift refresh
Slee
It is the reasoning, Jeff Atwood even said so himself during an SO podcast.
Chad Moran
+1  A: 

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.

Darin Dimitrov
So are you saying that the routing handler first looks for actual physical folder names before choosing a controller to route to? My tests seem to indicate that may be what is happening.
BC
+4  A: 

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

Marc Gravell
A: 

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.

Zhaph - Ben Duguid
But wouldn't Content/ queries match my default route?
BC
No, because you have no controller called ContentController for it to match.
Zhaph - Ben Duguid
+5  A: 

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.

Matt Woodard