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