【C#】以編程方式在IIS7中設(shè)置自定義標(biāo)識(shí)應(yīng)用程序池的用戶帳戶
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
在我的C#代碼中,我需要為我的Web應(yīng)用程序創(chuàng)建自定義標(biāo)識(shí)并將其添加到IIS 7,我執(zhí)行以下操作:
string strAppPoolName = "MyAppPool";
string strUserName = Environment.UserDomainName + "\\" + "myappusername";
addUserAccount(strUserName, strUserPass);
using (ServerManager serverManager = new ServerManager())
{
//Add application pool
ApplicationPool appPool = serverManager.ApplicationPools.Add(strAppPoolName);
appPool.AutoStart = true;
appPool.ManagedPipelineMode = ManagedPipelineMode.Integrated;
appPool.ManagedRuntimeVersion = "v4.0";
appPool.ProcessModel.MaxProcesses = 1;
//Assign identity to a custom user account
appPool.ProcessModel.IdentityType = ProcessModelIdentityType.SpecificUser;
appPool.ProcessModel.UserName = strUserName;
appPool.ProcessModel.Password = strUserPass;
} 將用戶添加到Active Directory的位置: public static void addUserAccount(string sUserName, string sPassword)
{
using (PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Domain))
{
using (UserPrincipal up = new UserPrincipal(oPrincipalContext))
{
up.SamAccountName = sUserName;
up.SetPassword(sPassword);
up.Enabled = true;
up.PasswordNeverExpires = true;
up.Description = "My app's user account";
up.Save();
}
}
} 問題是,當(dāng)我稍后將該站點(diǎn)和應(yīng)用程序添加到該應(yīng)用程序池下的IIS 7時(shí),Web應(yīng)用程序無(wú)法運(yùn)行,因?yàn)樗鼪]有足夠的權(quán)限。更重要的是,對(duì)于我來(lái)說(shuō),某些.NET類(例如System.Security.Cryptography)會(huì)因意外錯(cuò)誤代碼而失敗,即使我手動(dòng)將此新用戶帳戶的讀/寫權(quán)限設(shè)置為安裝了我的Web應(yīng)用程序的文件系統(tǒng)文件夾。 該文章在 2021/5/11 16:03:35 編輯過(guò) |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |