C# Start/Stop IIS Application pool programmatically with Access Denied issue

1

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.

c#
iis
application-pool
asked on Stack Overflow Nov 6, 2018 by Tak • edited Nov 6, 2018 by MickyD

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0