MVC如何在路由器(RouteConfig)定義后綴.html


一.配置文件web.config添加一下設置

<system.webServer>
   <modules runAllManagedModulesForAllRequests="true" />
</system.webServer>

 二.RouteConfig.cs設置

            routes.MapRoute(
                "Login",
                "Login.html",
                 new { controller = "Home", action = "Login" }
            );

            routes.MapRoute(
                "Index",
                "index.html",
                 new { controller = "Home", action = "Index" }
            );

            routes.MapRoute(
                "Default",
                "{controller}/{action}.html",
                new { controller = "Home", action = "Index"}
            );

 三.上面設置好后基本上已經完成了,但是運行時發現首頁不對,這個時候需要一下設置

在Global.asax文件里設置首頁

        //把首頁設置為重定向后的index.html地址
        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            if (Context.Request.FilePath == "/") Context.RewritePath("index.html");
        }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM