2015-11-03 79 views

回答

2

我的建議是不要做,使用ServerManager的,雖然有可能通過配置的API,你就不會被尊重供應商模式,IIS用戶的支持。例如,某人可能擁有「SQL Server」數據庫提供程序,然後用戶在配置中確實無法工作。

爲此,請在Microsoft.Web.Management.dll(在windows \ system32 \ inetsrv)文件夾中使用API​​,名爲ManagementAuthentication,它具有兩種方法:CreateUser和Grant。

我幾年前寫了一篇博客條目如何從PowerShell中稱他們爲: http://blogs.msdn.com/b/carlosag/archive/2009/10/23/adding-iis-manager-users-and-permissions-through-powershell.aspx

但稱他們是那麼容易,因爲:

Microsoft.Web.Management.Server.ManagementAuthentication.CreateUser("MyUser", "ThePassword"); 
Microsoft.Web.Management.Server.ManagementAuthorization.Grant("MyUser", "Default Web Site", false); 

這會正確使用哪個提供商配置,如果使用默認配置提供程序,那麼它會將其保存在Administration.config中,但如果它位於其他位置,它將執行正確的操作(例如將數據插入數據庫或其他位置)。

+0

我對這個建議有點問題。第一行確實創建了一個MyUser用戶。但是第二行似乎不足以讓用戶登錄。當我在IIS管理器中打開FTP站點(在運行您的建議代碼之後)時,我可以在我的FTP站點的「IIS管理器權限」中找到MyUser,但是我無法在「FTP授權規則」中找到它。因此,FTP登錄失敗並顯示消息「530-用戶無法登錄,主目錄無法訪問」。只要我將用戶添加到「FTP授權規則」中,它就開始工作。這發生在有和沒有FTP用戶隔離的情況下。幫幫我? – DenNukem

+0

哦,這保存了我的燻肉:[C:\ Windows \ system32 \ inetsrv \ appcmd.exe設置配置「MyFtpSite」 - 部分:system.ftpServer /安全/授權/ +「[accessType ='允許',users ='MyUser ',permissions ='讀取,寫入']「/ commit:apphost]如果沒有它,我將無法登錄。 – DenNukem

0

我最終做了這幾件事。在PowerShell中第一部分,每建議從卡洛斯:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Management") 
[Microsoft.Web.Management.Server.ManagementAuthentication]::CreateUser("MyUser", "abc123") 
[Microsoft.Web.Management.Server.ManagementAuthorization]::Grant("MyUser", "MyFtpSite", $FALSE) 

,然後這個命令行:

appcmd.exe set config "MyFtpSite" -section:system.ftpServer/security/authorization /+"[accessType='Allow',users='MyUser',permissions='Read, Write']" /commit:apphost 

所有的合併這些讓我添加一個新的IIS管理器用戶,並給它的權利我的FTP站點。

更多詳情,請登錄Microsoft site

相關問題