我创建了一个空的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/
答案 0 :(得分:1)
问题是因为您的路线没有正确设置为调用api。确保每个方法都有正确的路径(例如api / default / insert)。否则,如果您尝试呼叫直接控制器,它将显示此错误。
答案 1 :(得分:0)
确保您的控制器名称为default。检查WebApiConfig文件中的路由