36

我刚刚在我的服务器上发布了我的网站,但是当我在浏览器中键入 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>
4

2 回答 2

84

ASP.NET Web 窗体

web.config文件上,尝试使用clear之前的标签:

<system.webServer>
  <defaultDocument>
    <files>
      <clear />
      <add value="Pages/Home.aspx" />
    </files>
  </defaultDocument>
</system.webServer>

看看这里:http ://www.iis.net/configreference/system.webserver/defaultdocument

ASP.NET MVC / ASP.NET 核心

根据您使用的 asp.net mvc 版本,您可以将它放在不同的文件中(~/Global.asax.cs在 v3 或更早版本或~/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
        }
    );
}

它在ASP.NET CORE上类似。

看看这里: http: //www.codeproject.com/Articles/624181/Routing-Basics-in-ASP-NET-MVC

于 2013-08-01T19:22:56.763 回答
5

除了 Felipe 的回答之外,您还可以从 IIS 执行此操作。

选择Admin Tools--> IIS Manager--> 从列表中选择您的网站。单击Default Document右侧的 并单击Add。使用箭头将条目移动到列表顶部。你完成了。

但是,每次您发布网站时,这都会被覆盖。

于 2013-08-01T19:29:46.167 回答