简体   繁体   English

HTTP 403 Forbidden: Access is denied ASP.NET Web API

[英]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.您可以在将应用程序部署到生产环境时遵循此方法。

  1. Publish the application in release mode.以发布模式发布应用程序。
  2. Put your application in inetpub -- wwwroot folder because this folder have administrator rights.将您的应用程序放在 inetpub -- wwwroot 文件夹中,因为该文件夹具有管理员权限。

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尝试以下

  1. In Windows Explorer, locate the web.config file that is associated with the application.在 Windows 资源管理器中,找到与应用程序关联的 web.config 文件。
  2. Right-click the web.config file右键单击 web.config 文件
  3. Click Properties.单击属性。
  4. Click the Security tab, and then click Edit.单击安全选项卡,然后单击编辑。
  5. Click Add.单击添加。
  6. In the Enter the object names to select box, IUSR, click Check Names, and then click OK.在“输入要选择的对象名称”框 IUSR 中,单击“检查名称”,然后单击“确定”。
  7. Provide Full control, and then click OK.提供完全控制,然后单击确定。
  8. In the Web.config Properties dialog box, click OK.在 Web.config 属性对话框中,单击确定。

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:就我而言,尝试了几种解决方案,例如:

  1. Folder security and access rights, I gave IIS_USER access even to test gave everyone access on deployed folder also change IIS permission but no luck.文件夹安全和访问权限,我给了 IIS_USER 访问权限,甚至为了测试让每个人都访问已部署的文件夹也更改了 IIS 权限,但没有运气。
  2. Enabled "Directory Browsing" but no luck启用“目录浏览”但没有运气
  3. Enabled "Anonymous Authentication" but no luck启用“匿名身份验证”但没有运气
  4. Reinstall https SSL certificate since using https but no luck使用 https 重新安装 https SSL 证书但没有运气

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.

相关问题 错误403-禁止访问:拒绝访问。 ASP.NET - Error 403 - Forbidden: Access is denied. ASP.NET 在ASP.NET Web表单中最小化和捆绑CSS时出现“ 403-禁止访问:拒绝”错误 - “403 - Forbidden: Access is denied” error while minification and bundling of CSS in ASP.NET Web Forms MVC asp.net应用程序发布::错误:: 403-禁止:访问被拒绝 - MVC asp.net application published :: Error :: 403 - Forbidden: Access is denied IIS 10 Windows 服务器 2019 - 403 - 禁止:访问 ASP.NET MVC 站点时拒绝访问 - IIS 10 Windows Server 2019 - 403 - Forbidden: Access is denied when accessing ASP.NET MVC site HTTP状态403:禁止使用证书对ASP.NET Web服务进行身份验证的异常 - HTTP status 403: Forbidden exception using certificate to authenticate ASP.NET web service ASP.NET:403-禁止访问:被拒绝。 您无权使用您提供的凭据查看此目录或页面 - ASP.NET: 403 - Forbidden: Access is denied. You do not have permission to view this directory or page using the credentials that you supplied 403-禁止访问:拒绝访问 - 403 - Forbidden: Access is denied ASP.NET,AJAX - 403被禁止 - ASP.NET, AJAX - 403 forbidden ASP.Net 图像未显示(403:禁止) - ASP.Net Images Not Showing (403: Forbidden) ASP.NET开发服务器-禁止使用403 - ASP.NET Development Server - 403 Forbidden
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM