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

时光怂恿深爱的人放手 提交于 2019-12-22 04:29:14

问题


I'm getting the following error when running our ASP.NET Web API project on our production server.

403 - Forbidden: Access is denied. 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

403.14 - Directory listing denied.

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. ASP.Net MVC I have managed to get it working by adding runAllManagedModulesForAllRequests="true" to my web.config file.

<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.


回答1:


The above error will pop up when you do not have the permission to access the folder/web.config file.

Try the following

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.

I think it should work .




回答2:


In my case, someone deleted default Asp Net MVC Home/Index route in RouteConfig.

After placing this code back to the RouteConfig.cs in RegisterRoutes method the problem was gone.

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



回答3:


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.

Hopefully it should run.




回答4:


In case it helps anyone my issue was my publish options set to "Allow precompiled site to be updatable" and I was missing the file "PrecompiledApp.config" in my deployed API.




回答5:


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.



来源:https://stackoverflow.com/questions/40651176/http-403-forbidden-access-is-denied-asp-net-web-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!