I am going through "Routing Requests for Disk Files" part in Pro ASP.NET MVC 3 book and am facing a bit of a strange problem relating to a custom route constraint.
I created a custom route:
//82:1. this is added so that below routes are checked first before checking the disk files.
routes.RouteExistingFiles = true;
//82:2 the custom route which maps requests to Static/StaticContent.htm to route /Home/Content, only from IE.
routes.MapRoute("DiskFile", "Content/StaticContent.htm",
new { controller = "Home", action = "Content" },
new {customConstraint = new UserAgentConstraint("IE")},
new[] { "UrlsAndRoutes.Controllers" });
The book says that this route will let IE users view the Home/Content route and non-IE users view the Content/StaticContent.htm directly. It is NOT working for me that way.
Here is what is happening:
- I run the application and open the URL
http://localhost:50483/Content/StaticContent.htmin IE and am being re-routed to /Home/Content - I then open the URL
http://localhost:50483/Content/StaticContent.htmin Chrome and am being shown the original content of the StaticContent.htm - I then change to IE and press
Ctrl-R(refresh) OR select URL in url bar and pressEnterand am routed to original content of the StaticContent.htm (why?) - If I press
Ctrl-F5, then, I am being re-routed to /Home/Content (wut?)
Isn't the route supposed to send IE users, who try to access Content/StaticContent.htm, always to /Home/Content?
PS: I restarted Visual Studio and also deleted browser history on IE, but the issue persists.
UserAgentConstraint.cs
RegisterRoutes method in Global.asax.cs