HTTP 403禁止访问:拒绝访问ASP.NET Web API

问题描述 投票:8回答:5

在生产服务器上运行ASP.NET Web API项目时出现以下错误。

403 - 禁止访问:访问被拒绝。您无权使用您提供的凭据查看此目录或页面。

查看IIS 7.0错误日志的基础错误是

403.14 - 目录列表被拒绝。

我已经配置了生产服务器,因此它具有与登台服务器相同的设置(可以工作)。身份验证,模块,授权,权限等都是相同的。

根据这个线程中的建议403 - Forbidden: Access is denied. ASP.Net MVC我已经设法通过将runAllManagedModulesForAllRequests =“true”添加到我的web.config文件来使其工作。

<modules runAllManagedModulesForAllRequests =“true”>

虽然这有效但我不认为这是一个长期解决方案,因为它会在服务器上造成不必要的负担。

所以它似乎表明某些东西没有被加载应该被加载。

asp.net asp.net-mvc asp.net-web-api iis-7
5个回答
0
投票

当您没有访问文件夹/ web.config文件的权限时,将弹出上述错误。

请尝试以下方法

1.In Windows Explorer, locate the web.config file that is associated with the application. 
2.Right-click the web.config file 
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. 
7.Provide Full control, and then click OK. 
8.In the Web.config Properties dialog box, click OK.

我认为它应该有效。


0
投票

就我而言,有人在RouteConfig中删除了默认的Asp Net MVC Home / Index路由。

将此代码放回RegisterRoutes方法中的RouteConfig.cs后,问题就消失了。

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );

0
投票

在将应用程序部署到生产环境时,您可以遵循此方法。

  1. 在发布模式下发布应用程序。
  2. 将您的应用程序放在inetpub - wwwroot文件夹中,因为此文件夹具有管理员权限。

希望它应该运行。


0
投票

如果它帮助任何人我的问题是我的发布选项设置为“允许预编译的站点可更新”,我在我部署的API中缺少文件“PrecompiledApp.config”。


-1
投票

我们错过了部署配置,与应用程序关联的应用程序池不存在。我创建了一个具有相同名称的应用程序池,此错误已消失。

© www.soinside.com 2019 - 2024. All rights reserved.