2011-09-07 45 views
4

我尝试更改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管理器更改身份我没有得到任何错误。我的代码出了什么问题,为什么会出现此错误?

+0

分支和绑定和分离的担忧。你可以首先尝试调试,并只应用一个小的改变,看看CommitChanges是否工作或仍然失败?注释掉你的身份代码,看看你是否设法改变另一个属性... –

回答

2

对applicationHost.config的更新需要管理权限。当您在本地运行时,您是管理员。在云中,除非您提升角色,否则您的RoleEntryPoint将以普通用户身份运行。你有没有这样做?

检查您是否在您的角色声明的ServiceDefinition.csdef中指定了<Runtime executionContext="elevated"/>

编辑:韦德还展示了如何使用稍微不同的方法来做到这一点(检查注释)。 Try this as well

+0

谢谢!我试过这样做http://www.wadewegner.com/2011/01/programmatically-changing-the-apppool-identity-in-a-windows-azure-web-role/但我得到了另一个例外 –

相关问题