Nor*_*man 31 .net asp.net asp.net-mvc .net-core asp.net-core
我刚刚在我的服务器上发布了我的网站,但是当我在浏览器中输入www.mysite.com时,我收到此错误:HTTP错误403.14 - 禁止Web服务器配置为不列出此目录的内容.但是如果我键入www.mysite.com/Home.aspx它正确加载.那么,我该如何设置默认页面?我的web.config中已经有了这个:
<system.webServer>
<defaultDocument>
<files>
<add value="Pages/Home.aspx" />
</files>
</defaultDocument>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
Fel*_*ani 67
在web.config文件上,尝试使用clear之前的标记:
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="Pages/Home.aspx" />
</files>
</defaultDocument>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
看看这里:http://www.iis.net/configreference/system.webserver/defaultdocument
根据您使用的asp.net mvc的版本,您可以将其放在不同的文件中(~/Global.asax.csv3或更早版本或~/App_Start/RouteConfig.csv4或更高版本).在这两种情况下,您都会看到注册路由的内容,因为asp.net mvc使用路由而不是webforms等文件.因此,您可以更改默认值:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new
{
controller = "Home", // default controller
action = "Index", // default action on the controller
id = UrlParameter.Optional
}
);
}
Run Code Online (Sandbox Code Playgroud)
它与ASP.NET CORE类似.
看看这里:http://www.codeproject.com/Articles/624181/Routing-Basics-in-ASP-NET-MVC
除了 Felipe 的回答,您还可以从 IIS 执行此操作。
选择Admin Tools--> IIS Manager--> 从列表中选择您的网站。单击Default Document右侧的 并单击Add。使用箭头将条目移动到列表顶部。你完成了。
但是,每次您发布网站时,这都会被覆盖。
| 归档时间: |
|
| 查看次数: |
70701 次 |
| 最近记录: |