MVC设置默认页面
2024-08-30 21:54:29
方法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>
PS:iis设置的默认文档优先级要比web.config配置的默认文档高。
最新文章
- Delphi中字符串补齐方法
- html生成图片并保存到本地方法(Windows)
- form表单及其中元素
- PHP发送请求头和接收打印请求头
- 【转载】COM多线程原理与应用
- 关于resolve非泛型方法不能与类型实参一起使用
- Linux美化——终端提示符
- Linux shell 脚本中”2>;&;1″的含义解释
- CSS3学习系列之背景相关样式(一)
- Collections.synchronizedMap()、ConcurrentHashMap、Hashtable之间的区别
- shell打印 倒等腰三角形
- mysql常用
- telnet操作memcache
- quartz demo01
- 禁止textarea拉伸
- css3 box-sizing详解。
- [转] javaweb学习-jstl-<;c:forEach>;中 varStatus的属性简介
- restful_framework之APIView
- MemSQL Start[c]UP 2.0 - Round 1 E - Three strings 广义后缀自动机
- 如何在两个月的时间内发表一篇EI/SCI论文-我的时间管理心得