MVC通常規格書(のhttp:// localhostを:8149 /ホーム/インデックス)ルーティングの設定は次のよう:
時には、httpなどの需要:// localhostを:8149 /ホーム/インデックスがHTTPに変更:// localhostを:8149 / index.htmlを、それはより多くの静的なウェブサイトのように見えます
1
2
|
//配置首页 伪静态 路由
routes.MapRoute(
"pc_index"
,
"index.html"
,
new
{ controller =
"Home"
, action =
"Index"
});
|
但し
溶液(推奨しません)Web.configファイルを変更します。
1
2
3
4
|
<system.webServer>
<modules runAllManagedModulesForAllRequests=
"true"
>
</modules>
</system.webServer>
|
強くこのように推奨されない:
1、これらの問題の形ではなく要求(例えば.htmlの)をホストよりも、要求ごとに登録されたすべてのHTTPモジュールを実行することです。これは、モジュールが.JPG .GIFの.css .aspxの、など永遠に実行することを意味します
2、資源の浪費
3、およびグローバルな効果が間違っにつながる可能性があります
よりよい解決策(第二のアプローチ)
1
2
3
4
5
6
|
<system.webServer>
<modules >
<remove name=
"UrlRoutingModule-4.0"
/>
<add name=
"UrlRoutingModule-4.0"
type=
"System.Web.Routing.UrlRoutingModule"
preCondition=
""
/>
</modules>
</system.webServer>
|
よりよい解決策(第3のアプローチ)
1
2
3
4
5
|
<system.webServer>
<handlers>
<add name=
"htmlHandler"
verb=
"GET,HEAD"
path=
"*.html"
type=
"System.Web.StaticFileHandler"
/>
</handlers>
</system.webServer>
|
MVCルーティングパラメータを取得、異なる場所で、特別な方法を得るためのパラメータをルーティングは、それぞれ、同じではない、コントローラ内のルーティングパラメータを取得する方法についてここで述べた、クラス内の非コントローラ、およびビューで:
コントローラのルーティングパラメータに取得します。1.:
1
|
var
controller = RouteData.Values[
"controller"
];
//action,id或其他路由参数同理
|
ビューでゲット2:
1
|
<input type=
"text"
value=
"@Html.ViewContext.RouteData.Values["
controller
"]"
/>
|
非クラスコントローラ3.。
1
|
HttpContext.Current.Request.RequestContext.RouteData.Values[
"controller"
]
|