Identité d'installation pour une application Piscine en tant que LocalSystem Azure

StackOverflow https://stackoverflow.com/questions/9339743

  •  27-10-2019
  •  | 
  •  

Question

Est-il possible de le faire dans ServiceDefinition.csdef ou tout autre lieu sans aller à l'IIS et régler manuellement?

J'ai essayé executionContext="elevated" pour WebRole, ne fonctionne pas.

UPDATE

Si vous installez "IIS 6 Compatibilité avec la métabase" sur Azure IIS, la I erreur ci-dessous disparu.

Cette soulever une autre question, howto installer "IIS 6 Compatibilité avec la métabase" automatiquement au stade de déploiement sur Azure.


@astaykov, je aime commentaire mais le code ci-dessous trop grand, donc j'utiliser cet endroit.

J'utilise le même code écrit par Wade Wagner comme:

public override bool OnStart()
        {
            // http://code.msdn.microsoft.com/windowsazure/CSAzureChangeAppPoolIdentit-27099828
            // This variable is used to iterate through list of Application pools 
            string metabasePath = "IIS://localhost/W3SVC/AppPools";
            string appPoolName;
            using (ServerManager serverManager = new ServerManager())
            {
                //Get the name of the appPool that is created by Azure 
                appPoolName = serverManager.Sites[RoleEnvironment.CurrentRoleInstance.Id + "_Web"].Applications.First().ApplicationPoolName;
                // Get list of appPools at specified metabasePath location 
                using (DirectoryEntry appPools = new DirectoryEntry(metabasePath))
                {
                    // From the list of appPools, Search and get the appPool that is created by Azure  
                    using (DirectoryEntry azureAppPool = appPools.Children.Find(appPoolName, "IIsApplicationPool"))
                    {
                        if (azureAppPool != null)
                        {
                            // Refer to: 
                            // http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/e3a60d16-1f4d-44a4-9866-5aded450956f.mspx?mfr=true,  
                            // http://learn.iis.net/page.aspx/624/application-pool-identities/  
                            // for more info on AppPoolIdentityType 
                            azureAppPool.InvokeSet("AppPoolIdentityType", new Object[] { 0 });  // MD_APPPOOL_IDENTITY_TYPE_LOCALSYSTEM
                            // Write above settings to IIS metabase 
                            azureAppPool.Invoke("SetInfo", null);
                            // Commit the above configuration changes that are written to metabase 
                            azureAppPool.CommitChanges();
                        }
                    }
                }
            }
            RoleInRun = true;
            TaskInRun = false;
            return base.OnStart();
        }

Je peux obtenir la valeur rigth à appPoolName, mais l'erreur est arrivé ici: using (DirectoryEntry azureAppPool = appPools.Children.Find(appPoolName, "IIsApplicationPool"))

Je suis à la recherche des solutions partout mais ne peut pas trouver un indice Erreur ci-dessous, des événements IIS:

Application: WaIISHost.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Runtime.InteropServices.COMException
Stack:
   at System.DirectoryServices.DirectoryEntry.Bind(Boolean)
   at System.DirectoryServices.DirectoryEntry.Bind()
   at System.DirectoryServices.DirectoryEntry.get_IsContainer()
   at System.DirectoryServices.DirectoryEntries.Find(System.String, System.String)
   at GimmeRank.Redirector.WebRole.OnStart()
   at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.InitializeRoleInternal(Microsoft.WindowsAzure.ServiceRuntime.Implementation.Loader.RoleType)
   at Microsoft.WindowsAzure.ServiceRuntime.Implementation.Loader.RoleRuntimeBridge.<InitializeRole>b__0()
   at System.Threading.ExecutionContext.runTryCode(System.Object)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode, CleanupCode, System.Object)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()

Anyideas?

Était-ce utile?

La solution

ExecutionContext = « élevé » ne fonctionnera que votre RoleEntryPoint que le compte SYSTEM local, mais il est pas IIS identité du pool.

Vous pouvez vouloir vérifier ce blog par Wade Wagner . Ce qu'il décrit là, peut être exécuté dans votre méthode OnStart avec ExecutionContext = « élevé » (parce que seul administrateur peut changer l'identité de la piscine). Si cela ne fonctionne pas pour le système local, vous pouvez créer un utilisateur pour la RDP, il sera ajouté dans le groupe Administrateurs, et vous pouvez définir la iis identité du pool d'applications pour cet utilisateur.

UPDATE

Hm, j'utilisé la méthode suivante (qui est similaire) et il a bien fonctionné:

private void SetAppPoolIdentity()
{
    string appPoolUser = "myRDP_admin_user";
    string appPoolPass = "my_super_secure_password";

    Action<string> iis7fix = (appPoolName) =>
    {
        bool committed = false;
        while (!committed)
        {
            try
            {
                using (ServerManager sm = new ServerManager())
                {
                    var applicationPool = sm.ApplicationPools[appPoolName];
                    applicationPool.ProcessModel.IdentityType = ProcessModelIdentityType.SpecificUser;
                    applicationPool.ProcessModel.UserName = appPoolUser;
                    applicationPool.ProcessModel.Password = appPoolPass;
                    sm.CommitChanges();
                    committed = true;
                }
            }
            catch (FileLoadException fle)
            {
                Trace.TraceError("Trying again because: " + fle.Message);
            }
        }
    };

    // ServerManager in %WinDir%System32InetSrvMicrosoft.Web.Administration.dll
    var sitename = RoleEnvironment.CurrentRoleInstance.Id + "_Web";
    var appPoolNames = new ServerManager().Sites[sitename].Applications.Select(app => app.ApplicationPoolName).ToList();
    appPoolNames.ForEach(iis7fix);
}

Pourriez-vous essayer? Notez que cela ne fonctionnera pas avec le compte système local, car il ne compte réel et nous ne pouvons pas le mettre de cette façon (au moins je ne sais pas comment le faire, mais avec un compte spécifique pour RDP il fonctionne très bien).

Autres conseils

Créer start.cmd:

FOR /F "tokens=*" %%A IN ('%windir%/system32/inetsrv/APPCMD list wp /text:apppool.name') DO (

%systemroot%/system32/inetsrv/APPCMD set config /section:applicationPools /[name='%%A%':'].processModel.identityType:LocalSystem

)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top