Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cant add bindings to IIS programmatically - redirection.config permissions (with a video!)

Here is a video summary of my problem http://screencast.com/t/v6th4BuRLhV

I am trying to add bindings programmatically to IIS with this code:

public void AddBindings(string sitename, string hostname)
{
  ServerManager serverMgr = new ServerManager();

  Site mySite = serverMgr.Sites[sitename];

  mySite.Bindings.Add("*:80:" + hostname, "http");
  mySite.ServerAutoStart = true;

  serverMgr.CommitChanges();
}

And I get this error:

Filename: redirection.config
Error: Cannot read configuration file due to insufficient permissions

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: Filename: redirection.config
Error: Cannot read configuration file due to insufficient permissions


ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6 and IIS 7, and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

I have addressed the permissions on redirection.config (both IUSR and IIS_IUSRS have permissions)

enter image description here

As well as the errors on web.config as suggested here http://www.codeproject.com/Questions/348972/Error-Cannot-read-configuration-file-due-to-insuff

enter image description here

But it still doesn't work.

ANSWER

Websites don't run under the IIS group. Whoever owns the app pool is the user and this is the user that needs permission. Or put that user in the IIS_IUSRS group.

like image 745
Petras Avatar asked Jun 22 '14 14:06

Petras


2 Answers

Figure out what account your application pool is running as. Then you need to give that account access to the entire %SystemRoot%\System32\inetsrv\config folder. It wasn't enough for me to give access to just %SystemRoot%\System32\inetsrv\config\redirection.config

like image 69
nthpixel Avatar answered Oct 24 '22 21:10

nthpixel


in my case "run as administrator" solved the problem

like image 37
David Avatar answered Oct 24 '22 21:10

David