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");
        }

 

posted @ 2016-03-28 14:51  苦逼的猿人  阅读(3141)  评论(0编辑  收藏  举报