views:

180

answers:

1

I am looking to generate some CSS files dynamically in my Content folder.

At the moment, this folder has an ignore route (routes.IgnoreRoute("Content/{*wildcard}");) and, I'd like that to remain, as I don't need/want most of my content folders to go into the MVC request lifecycle.

Example:

 routes.MapRoute(
  "DynamicCSS",
  "Content/Css/Dynamic/{guid}.css",
  new { controller = "Site", action = "GenerateCSS" },
  new { guid = @"^([0-9a-fA-F]){8}([0-9a-fA-F]){4}([0-9a-fA-F]){4}([0-9a-fA-F]){4}([0-9a-fA-F]){12}$" }
);

//If the file has already been generated, IIS should just return the file, saving a request in MVC.
routes.RouteExistingFiles = true; //was formerly false

//Ignore routes
routes.IgnoreRoute("Content/{*wildcard}");

I have a couple questions/concerns about this setup:

  • Will this work? Routes in ASP.NET MVC are lazy, but I don't know if the ignore routes are checked first. There's no documentation (I've Googled!) on this form of usage.
  • Are there any security implications to consider when switching on RouteExistingFiles? I don't want IIS to pick up any of my Model/Views folders by directly referencing them.

Many thanks for any suggestions.

Edit:

After further research, I have found an article on my first issue.

+2  A: 

Scott Hanselman got a blog post "Plug-In Hybrids: ASP.NET WebForms and ASP.MVC and ASP.NET Dynamic Data Side By Side" in which he talked about his too. http://www.hanselman.com/blog/PlugInHybridsASPNETWebFormsAndASPMVCAndASPNETDynamicDataSideBySide.aspx

Hope this helps,

Ray.

ray247