首页 > 解决方案 > 为从 Visual Studio 发布的 ASP.NET 项目启用目录浏览

问题描述

我正在尝试导入一个我知道有效的 ASP.NET 项目,并且我正在尝试在本地构建它。我在 Visual Studio 中导入了解决方案文件并继续并对其进行了清理和构建,一切正常。现在我正在尝试发布项目,一旦我这样做了,我点击了运行按钮,上面写着 IIS Express,我看到了以下内容

HTTP Error 403.14 - Forbidden

Most likely causes:
A default document is not configured for the requested URL, and directory browsing is not enabled on the server.

如果我在 IIS 管理器中运行此应用程序,我知道如何通过单击项目、单击目录浏览并单击启用来解决此问题,但如果我从 Visual Studio 中运行它,我不知道如何解决此问题。

标签: asp.netvisual-studioiishttp-status-code-403

解决方案


要解决此问题,您可以尝试以下方法之一:

1)在web.config文件中设置如下代码:

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="true" />
</system.webServer>

2)为您的项目设置默认页面:

<system.webServer>
  <defaultDocument>
    <files>
      <add value="pagename.aspx" />
    </files>
  </defaultDocument>
</system.webServer>

如果您使用的是 MVC 站点,则设置默认路由。


推荐阅读