Jonas Sourlier
Jonas Sourlier

Reputation: 14435

ASP.NET WebAPI deployed to IIS: Access to web.config denied (IIS searches in wrong path)

I have an ASP.NET MVC/WebAPI mixed project which runs just fine in the VS2012 development server. It has a standard MVC {controller}/{action}/{id} route, as well as an additional WebAPI route api/{controller}/{id}. Requests which start with /api/... are directed to WebAPI, the others to normal MVC.

When I deploy it to the local IIS, the normal MVC routes are working. However, /api calls to WebAPI are resulting in the exception

Access to the path 'C:\inetpub\wwwroot\myapp\web.config' is denied.

Then I tried to set the proper security permissions on the inetpub folder and its subfolders. This didn't help anything, and because the normal MVC requests are working, I don't suspect the problem to be security-related.

Then I started Sysinternals Process Monitor to see what w3wp.exe is doing during the request. As it turns out, IIS looks for web.config here:

C:\inetpub\wwwroot\myapp\api\web.config
C:\inetpub\wwwroot\myapp\api\mycontroller\web.config

Of course, there is no web.config there.

How can I set up IIS to recognize both routes?

Upvotes: 0

Views: 4209

Answers (1)

Drisan James
Drisan James

Reputation: 156

I do not believe this is a problem with your routing. the problem is the permissions given to IIS I run into this error from time to time. Depending on the app pool identity you are running under you need to provide permissions to that entity. Here is a link to a very thorough explanation

IIS AppPoolIdentity and file system write access permissions

Basically right click your project folder, go to properties, click the security tab and and you will see Group or user names. These are the allowed entities to perform read and/or write actions to that directory. Click Edit then Add; from here you will then "Enter the object names to select" typically IIS follows under IIS_IUSRS again this depends on your app pool configuration from here you should move on from the error mentioned!

I hope this helps!

Upvotes: 1

Related Questions