I'm writing a function which will determine whether a particular web application exists in IIS. It works by iterating through the available sites and then checks if the particular key is in the ApplicationsCollection array:
String application_name = "some_application_name";
ServerManager iis = new ServerManager();
try
{
foreach (Site site in iis.Sites)
{
Application app = site.Applications[application_name];
}
}
catch (Exception e)
{
Console.WriteLine("Error reading site from site list" + e.Message);
}
However when i run this code, i get the following error:
Error: Cannot read configuration file due to insufficient permissions
I am currently running the application under my own windows user. All websites in IIS run under ApplicationPoolIdentity and have Anonymous Authentication set to IUSR.
Any suggestions as to how i can work around this error?