mvc路由配置 html結尾的偽靜態

2022-08-04 20:21:17 字數 686 閱讀 5019

mvc 標準的寫法 通常是(http://localhost:8149/home/index) 路由配置如下:

有時候需求 如 http://localhost:8149/home/index 改為http://localhost:8149/index.html 讓其看起來更加像乙個靜態**

//配置首頁 偽靜態 路由

routes.maproute("pc_index", "index.html", new );

然而

解決方式一(不建議)修改 web.config 檔案  

這種方式強烈不建議:1、這些問題的形式是使所有註冊的http模組在每個請求上執行,而不僅僅是託管請求(例如.html)。 這意味著模組將永遠執行.jpg .gif .css .aspx等2、浪費資源

3、並具有可能導致錯誤的全域性效應

更好的解決方案(方式二)

更好的解決方案(方式三)

MVC 偽靜態路由

定義url html.actionlink html get page new 這url是呼叫本控制器下面的的get page方法,傳參id 定義路由 routes.maproute name urlhtml url html 註冊路由 routeconfig.registerroutes rout...

mvc 路由偽靜態實現

很多 都採用偽靜態,例如以html shtml等結尾的url,mvc的路由可以輕鬆實現。mvc的路由原理是從上往下匹配的,所以只需要在後面新增自己配置的路由即可 public static void registerroutes routecollection routes axd routes.m...

mvc 路由偽靜態實現

很多 都採用偽靜態,例如以html shtml等結尾的url,mvc的路由可以輕鬆實現。mvc的路由原理是從上往下匹配的,所以只需要在後面新增自己配置的路由即可 public static void registerroutes routecollection routes axd routes.m...