我嘗試更改Windows Azure上應用程序池的標識。在使用Windows Azure時,我的項目使用此應用程序池。默認情況下,應用程序池使用NetworkService標識,但我必須使用其他標識。我試圖通過這種方式改變它在OnStart()
事件WebRole的:更改應用程序池標識時出錯
using (ServerManager serverManager = new ServerManager())
{
string appPoolName =
serverManager.Sites[RoleEnvironment.CurrentRoleInstance.Id + "_Web"]
.Applications.First().ApplicationPoolName;
var appPool = serverManager.ApplicationPools[appPoolName];
appPool.ProcessModel.UserName = Environment.MachineName + "\\UserName";
appPool.ProcessModel.IdentityType = ProcessModelIdentityType.SpecificUser;
appPool.ProcessModel.Password = "UserPassword";
serverManager.CommitChanges();
}
,但我得到的異常與下一條消息:
System.Runtime.InteropServices.COMException (0x80090016):
Keyset does not exist (Exception from HRESULT: 0x80090016)
at Microsoft.Web.Administration.Interop.AppHostWritableAdminManager.CommitChanges()
at Microsoft.Web.Administration.Configuration.CommitChanges()
at Microsoft.Web.Administration.ConfigurationManager.CommitChanges()
at Microsoft.Web.Administration.ServerManager.CommitChanges()
at Project.Web.WebRole.OnStart() in E:\Projects\...\Web\WebRole.cs:line 57
如果我在IIS管理器更改身份我沒有得到任何錯誤。我的代碼出了什麼問題,爲什麼會出現此錯誤?
分支和綁定和分離的擔憂。你可以首先嚐試調試,並只應用一個小的改變,看看CommitChanges是否工作或仍然失敗?註釋掉你的身份代碼,看看你是否設法改變另一個屬性... –