RouteExistingFiles and IgnoreRoute in asp.net mvc

. Thursday, March 24, 2011
  • Agregar a Technorati
  • Agregar a Del.icio.us
  • Agregar a DiggIt!
  • Agregar a Yahoo!
  • Agregar a Google
  • Agregar a Meneame
  • Agregar a Furl
  • Agregar a Reddit
  • Agregar a Magnolia
  • Agregar a Blinklist
  • Agregar a Blogmarks


How to Use RouteExistingFile and IgnoreRoute in asp.net mvc.

RouteExistingFile is a property of Routecollection class Which is True or false.
eg: routes.RouteExistingFiles = true

as you can see all css have been acting as route and hence no longer available for Home/
whenever you write this it routes the files present on your harddisk which in turns acts as a route.
for example if you have css in /content/file.css and you make RouteExistingFiles true then it will match
{controller}/{action} url for file.css and this will no longer available for existing pages.

Only two cases are possible to get file.css
1)if you directly hit that file eg:/content/file.css
2)if you use routes.Ignore route.

Case 1 is quite simple

Case 2 routes.IgnoreRoute is and extended method which accepts routes to be ignored and below will
ignore the route matching for css.
eg:
routes.IgnoreRoute("{Content}/{file.css}")
as shown in above figure now those files present on hard drive not acting as route and available for pages.

Thanks friends see you soon

0 comments: