首页 > Web开发 > 详细

MVC设置默认页面的几个方法

时间:2015-04-13 12:45:19      阅读:231      评论:0      收藏:0      [点我收藏+]

方法1:在RouteConfig.cs文件中配置默认路由

public class RouteConfig
{
      public static void RegisterRoutes(RouteCollection routes)
      {
          routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

          routes.MapRoute(
              name: "Default",
              url: "{controller}/{action}/{id}",
              defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
          );
      }
}

 

方法2:在Global文件中添加方法

protected void Application_BeginRequest(object sender, EventArgs e)
{
    if (Context.Request.FilePath == "/")
        HttpContext.Current.Response.Redirect("/home/about");
}

 

方法3:在web.config中配置节点;这个方法不支持路由,默认文档需放在网站根目录下,类型可以是.php, .asp, .htm, .aspx, .cfm等等

<system.webServer>
    <defaultDocument>
      <files>
        <clear/><!--防止在iis配置默认文档中冲突-->
        <add value="index.html" />
      </files>
    </defaultDocument>
</system.webServer>

 

MVC设置默认页面的几个方法

原文:http://www.cnblogs.com/paulhe/p/4421822.html

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