天天看點

mvc實作僞靜态

1 MVC如何實作僞靜态?

下面進入主題,我們大家都知道asp.net MVC的URL預設的都是 域名+控制器名稱+Action名稱,有的人說,直接在action後面加一個.html就好了,好我們就這麼做了

<span style="white-space:pre">	</span>public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
 
            routes.MapRoute(
               name: "Default",
               url: "{controller}/{action}.html",
               defaults: new { controller = "Home", action = "Index" }
           );
        }
           

2.浏覽器意外的報了 http 404錯誤

<system.webServer>

下  加入

<handlers>

<add name="HtmlFileHandler" path="*.html" verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>

</handlers>

繼續閱讀