簡體   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