I would like to Allow the Existing IIS Manager User to a IIS Site or Website Using C# .
anyone can share the sample code . It would be really helpful .
Look at the image I want to add those users programmatically .
Thank You, Jaswanth
I would like to Allow the Existing IIS Manager User to a IIS Site or Website Using C# .
anyone can share the sample code . It would be really helpful .
Look at the image I want to add those users programmatically .
Thank You, Jaswanth
My recommendation would be not to do that using ServerManager, although possible through config APIs, you would not be respecting the provider model that IIS Users support. For example someone could have a "SQL Server" database provider and then your users in config really would not work.
To do that properly you use an API in Microsoft.Web.Management.dll (in windows\system32\inetsrv) folder, called ManagementAuthentication which has two methods for that: CreateUser, and Grant.
I wrote a blog entry a few years ago on how to call them from PowerShell: http://blogs.msdn.com/b/carlosag/archive/2009/10/23/adding-iis-manager-users-and-permissions-through-powershell.aspx
But calling them is as easy as:
Microsoft.Web.Management.Server.ManagementAuthentication.CreateUser("MyUser", "ThePassword");
Microsoft.Web.Management.Server.ManagementAuthorization.Grant("MyUser", "Default Web Site", false);
This will correctly use whichever provider is configured, and if the default configuration provider is used then that will save it in Administration.config, but if it was somewhere else it would do the right thing (such as inserting the data in a database or elsewhere).
I ended up doing these several things. First part in powershell, per advice from Carlos:
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Management")
[Microsoft.Web.Management.Server.ManagementAuthentication]::CreateUser("MyUser", "abc123")
[Microsoft.Web.Management.Server.ManagementAuthorization]::Grant("MyUser", "MyFtpSite", $FALSE)
and then this from the command line:
appcmd.exe set config "MyFtpSite" -section:system.ftpServer/security/authorization /+"[accessType='Allow',users='MyUser',permissions='Read, Write']" /commit:apphost
All combined these allow me to add a new IIS Manager User, and give it rights to my FTP site.
More details at Microsoft site.