[英]Custom route constraint issue in ASP.NET MVC
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. 我正在阅读Pro ASP.NET MVC 3书中的“磁盘文件路由请求”部分,并且遇到了一个与自定义路由约束有关的奇怪问题。
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. 该书说,此路由将使IE用户可以查看“家庭/内容”路由,非IE用户可以直接查看Content / StaticContent.htm。 It is NOT working for me that way.
这样对我不起作用。
Here is what is happening: 这是正在发生的事情:
http://localhost:50483/Content/StaticContent.htm
in IE and am being re-routed to /Home/Content http://localhost:50483/Content/StaticContent.htm
,然后将其重新路由到/ Home / Content http://localhost:50483/Content/StaticContent.htm
in Chrome and am being shown the original content of the StaticContent.htm http://localhost:50483/Content/StaticContent.htm
,并显示了StaticContent.htm的原始内容 Ctrl-R
(refresh) OR select URL in url bar and press Enter
and am routed to original content of the StaticContent.htm ( why? ) Ctrl-R
(刷新),或者在网址栏中选择URL,然后按Enter
然后将其路由到StaticContent.htm的原始内容( 为什么? ) Ctrl-F5
, then, I am being re-routed to /Home/Content ( wut? ) Ctrl-F5
,那么我将被重新路由到/ Home / Content( wut? ) Isn't the route supposed to send IE users, who try to access Content/StaticContent.htm, always to /Home/Content? 路由是否不应该将试图访问Content / StaticContent.htm的IE用户始终发送到/ Home / Content?
PS: I restarted Visual Studio and also deleted browser history on IE, but the issue persists . PS:我重新启动了Visual Studio,还删除了IE上的浏览器历史记录, 但问题仍然存在 。
UserAgentConstraint.cs UserAgentConstraint.cs
RegisterRoutes method in Global.asax.cs Global.asax.cs中的RegisterRoutes方法
It's probably being cached 它可能正在缓存
Ctrl+F5 makes it ask server for reload even if content haven't changed. Ctrl + F5使其即使内容未更改也要求服务器重新加载。
It sounds like this is correct behaviour. 听起来这是正确的行为。
Verify by making changes to static.html after first reload. 首次重新加载后,通过对static.html进行更改来进行验证。 Then Ctrl+R reload.
然后按Ctrl + R重新加载。 It should hit the action method.
应该打动作方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.