I'm trying to simply start/stop the application pool in IIS programmatically in C# in the following code:
ServerManager serverManager = new ServerManager();
ApplicationPoolCollection appPools = serverManager.ApplicationPools;
foreach (ApplicationPool ap in appPools)
{
if (ap.Name == "Test App")
ap.Start();
}
I already added the assembly Microsoft.Web.Administration in the project. And I also gave the full permission for user "IIS AppPool\DefaultAppPool" in the folder C:\Windows\System32\inetsrv\config. (Before giving this permission, it's not even able read the application pool name.)
However, it's still throw an exception when it's trying to start the application pool.
An unhandled exception of type 'System.UnauthorizedAccessException' occurred in Microsoft.Web.Administration.dll
Additional information: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
What else permission should I need to add for fixing it? Thanks.
User contributions licensed under CC BY-SA 3.0