私は、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 ユーザーは Home/Content ルートを表示し、IE 以外のユーザーは Content/StaticContent.htm を直接表示できるようになります。それは私にとってはうまくいきません。
何が起こっているかは次のとおりです。
- アプリケーションを実行して IE で URL を開くと、
http://localhost:50483/Content/StaticContent.htm
/Home/Content に再ルーティングされます - 次に、Chrome で URL を開く
http://localhost:50483/Content/StaticContent.htm
と、StaticContent.htm の元のコンテンツが表示されています。 - 次に、IE に変更して
Ctrl-R
(更新) を押すか、URL バーで URL を選択して押すEnter
と、StaticContent.htm の元のコンテンツにルーティングされます (なぜですか? ) - を押す
Ctrl-F5
と、/Home/Content に再ルーティングされます ( wut? )
ルートは、Content/StaticContent.htm にアクセスしようとする IE ユーザーを常に /Home/Content に送るはずではないでしょうか?
PS: Visual Studio を再起動し、IE のブラウザー履歴も削除しましたが、問題は解決しません。