【问题标题】:A default document is not configured for the requested URL Web Api 2 / IIS express未为请求的 URL Web Api 2 / IIS express 配置默认文档
【发布时间】:2017-07-07 17:16:41
【问题描述】:

我创建了一个空的 web api 2 项目并创建了一个默认控制器。当我尝试转到我的控制器时,我得到了

HTTP Error 403.14 - Forbidden
The Web server is configured to not list the contents of this directory.

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

Things you can try:
If you do not want to enable directory browsing, ensure that a default document is configured and that the file exists.
Enable directory browsing.
Go to the IIS Express install directory.
Run appcmd set config /section:system.webServer/directoryBrowse /enabled:true to enable directory browsing at the server level.
Run appcmd set config ["SITE_NAME"] /section:system.webServer/directoryBrowse /enabled:true to enable directory browsing at the site level.
Verify that the configuration/system.webServer/directoryBrowse@enabled attribute is set to true in the site or application configuration file.

Detailed Error Information:
Module     DirectoryListingModule
Notification       ExecuteRequestHandler
Handler    StaticFile
Error Code     0x00000000
Requested URL      http://localhost:49886/api/default/
Physical Path      C:\Users\Source\Repos\ospapi\OSP.Api\OSP.Api\
Logon Method       Anonymous
Logon User     Anonymous
Request Tracing Directory      C:\Users\Documents\IISExpress\TraceLogFiles\OSP.API

More Information:
This error occurs when a document is not specified in the URL, no default document is specified for the Web site or application, and directory listing is not enabled for the Web site or application. This setting may be disabled on purpose to secure the contents of the server.
View more information »

我的网址:http://localhost:49886/api/default/

【问题讨论】:

  • 你设置了默认路由吗?

标签: asp.net asp.net-web-api asp.net-web-api2 iis-express


【解决方案1】:

问题是因为你的路由没有正确设置为调用 api。确保每个方法都有正确的路径(例如 api/default/insert)。否则,如果您尝试调用直接控制器,它将显示此错误。

【讨论】:

    【解决方案2】:

    确保您有一个名称为 default 的控制器。检查 WebApiConfig 文件中的路由

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-06
      • 1970-01-01
      • 2015-06-14
      • 2020-02-16
      • 2013-12-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多