[英]HTTP 403 Forbidden: Access is denied ASP.NET Web API
I'm getting the following error when running our ASP.NET Web API project on our production server.在我们的生产服务器上运行我们的 ASP.NET Web API 项目时,我收到以下错误。
403 - Forbidden: Access is denied.
403 - 禁止:访问被拒绝。 You do not have permission to view this directory or page using the credentials that you supplied.
您无权使用您提供的凭据查看此目录或页面。
Looking at the IIS 7.0 error logs the underlying error is查看 IIS 7.0 错误日志,底层错误是
403.14 - Directory listing denied.
403.14 - 目录列表被拒绝。
I have configured the production server so it has the same settings as the staging server (which works).我已经配置了生产服务器,因此它与临时服务器具有相同的设置(工作正常)。 The authentication, modules, authorization, permissions etc are all identical.
身份验证、模块、授权、权限等都是相同的。
Following a suggestion in this thread 403 - Forbidden: Access is denied.遵循此线程中的建议403 - Forbidden: Access is denied。 ASP.Net MVC I have managed to get it working by adding runAllManagedModulesForAllRequests="true" to my web.config file.
ASP.Net MVC我设法通过将runAllManagedModulesForAllRequests="true"添加到我的 web.config 文件来让它工作。
<modules runAllManagedModulesForAllRequests="true">
<modules runAllManagedModulesForAllRequests="true">
Whilst this works I don't see this as a long term solution as it will cause unnecessary load on the server.虽然这有效,但我不认为这是一个长期的解决方案,因为它会导致服务器上不必要的负载。
So it seems to indicate that something isn't getting loaded that should be getting loaded.所以它似乎表明有些东西没有被加载,而应该被加载。
In my case, someone deleted default Asp Net MVC Home/Index route in RouteConfig.就我而言,有人在 RouteConfig 中删除了默认的 Asp Net MVC Home/Index路由。
After placing this code back to the RouteConfig.cs in RegisterRoutes method the problem was gone.将此代码放回 RegisterRoutes 方法中的 RouteConfig.cs 后,问题就消失了。
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
You can follow this approach while deploying the application to production environment.您可以在将应用程序部署到生产环境时遵循此方法。
Hopefully it should run.希望它应该运行。
The above error will pop up when you do not have the permission to access the folder/web.config file.当您没有权限访问文件夹/web.config 文件时,将弹出上述错误。
Try the following尝试以下
I think it should work .我认为它应该工作。
如果它对任何人有帮助,我的问题是我的发布选项设置为“允许预编译站点可更新”,而我在部署的 API 中缺少文件“PrecompiledApp.config”。
I recently faced same issue while configuring my site on iis (https).我最近在 iis (https) 上配置我的网站时遇到了同样的问题。 In my case, tried several solutions like:
就我而言,尝试了几种解决方案,例如:
and several hit and try and at last I found!!!!并尝试了几次,最后我找到了!!!!
It was very tiny problem I choose " Precompile during publishing " while publishing my website/APIs and when i unchecked this option everything become normal and start working fine, not sure actual reason why this happen but to resolve you may try as showing in picture (visual studio 2019) below:这是一个非常小的问题,我在发布我的网站/API 时选择了“发布期间预编译”,当我取消选中此选项时,一切都变得正常并开始正常工作,不确定发生这种情况的实际原因,但要解决您可以尝试如图所示( Visual Studio 2019)如下:
My specific situation was that I had basic authentication and on the API controller in the Authorize decorator the role did not matchup with the role of the user I supplied for authentication.我的具体情况是我进行了基本身份验证,并且在 Authorize 装饰器中的 API 控制器上,角色与我为身份验证提供的用户角色不匹配。 eg.
例如。 [Authorize(AuthenticationSchemes =BasicAuthenticationHandler.SchemeName , Roles = "Tester") ]
[授权(AuthenticationSchemes =BasicAuthenticationHandler.SchemeName,角色=“测试者”)]
We missed deployment configuration, application pool associated with the application not exists.我们错过了部署配置,与应用程序关联的应用程序池不存在。 I created an application pool with the same name and this error has gone away.
我创建了一个同名的应用程序池,这个错误消失了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.