首页 > 布布扣 > 详细

MVC首页实现静态化后,无静态页面时默认原路由规则实现方案

时间:2014-12-02 16:51:39      阅读:1589      评论:0      收藏:0      [点我收藏+]

mvc3中,将首页实现了静态化,生成静态文件如index.html,在无静态文件时系统自动运行路由规则的页面。具体,如tech.bubufx.com,当存在index.html时运行index.html,当删除了该静态文件后,运行未实现静态化的程序如tech.bubufx.com/home/index,自动。


protected void Application_BeginRequest(Object sender, EventArgs e)
{
    if (Context.Request.FilePath == "/") Context.RewritePath("index.html");
}

增加路由规则:

      routes.MapRoute(
                "html", // Route name
                "{action}.html", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
                , new[] { "bubufx.Controllers" }//默认命名空间
            );


MVC首页实现静态化后,无静态页面时默认原路由规则实现方案

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!