Beispiel #1
0
        /// <summary>
        /// This method iterates over the used application pools of the Azure Cloud Services Web role and changes the application pool account from NETWORK to SYSTEM. This is
        /// needed to make to code work with the Microsoft Online Services Sign In Assistant
        /// </summary>
        private void SetAppPoolIdentity()
        {

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

            var sitename = RoleEnvironment.CurrentRoleInstance.Id + "_Web";
            var appPoolNames = new ServerManager().Sites[sitename].Applications.Select(app => app.ApplicationPoolName).ToList();
            appPoolNames.ForEach(iis7fix);
        }