繁体   English   中英

ASP.NET MVC中的自定义路由约束问题

[英]Custom route constraint issue in ASP.NET MVC

我正在阅读Pro ASP.NET MVC 3书中的“磁盘文件路由请求”部分,并且遇到了一个与自定义路由约束有关的奇怪问题。

我创建了一条自定义路线:

//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" });

该书说,此路由将使IE用户可以查看“家庭/内容”路由,非IE用户可以直接查看Content / StaticContent.htm。 这样对我不起作用。

这是正在发生的事情:

  1. 我运行该应用程序并在IE中打开URL http://localhost:50483/Content/StaticContent.htm ,然后将其重新路由到/ Home / Content
  2. 然后,我在Chrome中打开URL http://localhost:50483/Content/StaticContent.htm ,并显示了StaticContent.htm的原始内容
  3. 然后,我更改为IE,然后按Ctrl-R (刷新),或者在网址栏中选择URL,然后按Enter然后将其路由到StaticContent.htm的原始内容( 为什么?
  4. 如果按Ctrl-F5 ,那么我将被重新路由到/ Home / Content( wut?

路由是否不应该将试图访问Content / StaticContent.htm的IE用户始终发送到/ Home / Content?

PS:我重新启动了Visual Studio,还删除了IE上的浏览器历史记录, 但问题仍然存在

UserAgentConstraint.cs
Global.asax.cs中的RegisterRoutes方法

它可能正在缓存

Ctrl + F5使其即使内容未更改也要求服务器重新加载。

听起来这是正确的行为。

首次重新加载后,通过对static.html进行更改来进行验证。 然后按Ctrl + R重新加载。 应该打动作方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM