23

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?

BC.
  • 24,298
  • 12
  • 47
  • 62
  • @BC, I asked the same question cause I was curious too. About the css files that is. Check out: http://stackoverflow.com/questions/502600/versioning-css-files-with-a-query-string-like-stackoverflow-does – mmcdole Feb 23 '09 at 10:57

5 Answers5

19

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
  • 1,956
  • 1
  • 16
  • 13
5

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
  • 1,026,079
  • 266
  • 2,566
  • 2,900
4

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
  • 34,696
  • 4
  • 39
  • 58
3

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
  • 26,785
  • 5
  • 80
  • 117
1

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
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • 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. Feb 22 '09 at 20:10