Как получить свойство "Режим запуска" запущенного AppPool

fabian09 спросил: 31 июля 2018 в 09:46 в: c#

Я пишу мир кода в том, что я проверяю определенные свойства запущенного AppPool. До сих пор я получил "Enable32BitAppOnWin64" "IdentityType" "UserName" и "Password". Теперь я пытаюсь получить свойство "Режим запуска". Но я не могу найти это свойство на любом уровне. Кто-нибудь знает, как получить это?

namespace Automated_Tests {class AppPoolUser {

    Output_Handler OutputHandler = new Output_Handler();    public string ServiceUser { get; set; } = ".\\Administrator";
    public string ServiceUserPassword { get; set; } = "admin";    public void ExecuteAppPoolUserCheck()
    {
        CheckExistingApplicationPool("Platform Services (RO) App Pool", true);
        CheckExistingApplicationPool("Platform Services App Pool", true);
        CheckExistingApplicationPool("Processes App Pool", false);
        CheckExistingApplicationPool("Settings App Pool", true);
        CheckExistingApplicationPool("Web App Pool", true);
    }    private void CheckExistingApplicationPool(string applicationPoolName, bool is64Bit)
    {
        ApplicationPool applicationPool = GetApplicationPool(applicationPoolName);        if (applicationPool != null)
        {
            if (is64Bit)
            { CheckAppPoolBitnessfor64BitAppPool(applicationPool); }
            else { CheckAppPoolBitnessfor32BitAppPool(applicationPool); }
        }
        else
        {
            return;
        }
        CheckApplicationPoolUser(applicationPool);
        CheckApplicationPoolStartMode(applicationPool);
    }    private ApplicationPool GetApplicationPool(string appPoolName)
    {
        var serverManager = new ServerManager();        try
        {
            ApplicationPool appPool = serverManager.ApplicationPools[appPoolName];
            return appPool;
        }
        catch (Exception ex)
        {            logger.Debug(ex, "Application Pool " + serverManager.ApplicationPools[appPoolName] + " does not exist");
            return null;
        }    }    private void CheckAppPoolBitnessfor32BitAppPool(ApplicationPool applicationPool)
    {
        //boolean == true 
        if (applicationPool.Enable32BitAppOnWin64)
        {
            OutputHandler.ColorCMDOutput("The AppPoolBitness 32Bit is correctly set for " + applicationPool.Name, ConsoleColor.Green);
        }
        else
        {
            OutputHandler.ColorCMDOutput("The AppPoolBitness 32Bit is NOT correctly set for " + applicationPool.Name, ConsoleColor.Red);
            OutputHandler.AppendDataToFile(@"C:\Users\Public\TestFolder\Buglist.txt", "The AppPoolBitness 32BIT is NOT correctly set for " + applicationPool.Name);
        }
    }    private void CheckAppPoolBitnessfor64BitAppPool(ApplicationPool applicationPool)
    {
        //boolean == false 
        if (!applicationPool.Enable32BitAppOnWin64)
        {
            OutputHandler.ColorCMDOutput("The AppPoolBitness 64BIT is correctly set for " + applicationPool.Name, ConsoleColor.Green);
        }
        else
        {
            OutputHandler.ColorCMDOutput("The AppPoolBitness 64BIT is NOT correctly set for " + applicationPool.Name, ConsoleColor.Red);
            OutputHandler.AppendDataToFile(@"C:\Users\Public\TestFolder\Buglist.txt", "The AppPoolBitness 64BIT is NOT correctly set for " + applicationPool.Name);
        }
    }    private void CheckApplicationPoolUser(ApplicationPool applicationPool)
    {
        if (applicationPool.ProcessModel.IdentityType != ProcessModelIdentityType.SpecificUser)
        {
            OutputHandler.ColorCMDOutput("The AppPoolIdentitytype \"SpecificUser\" is NOT correctly set for " + applicationPool.Name + ". The currently Set value is \"" + applicationPool.ProcessModel.IdentityType.ToString() + "\"", ConsoleColor.Red);
            OutputHandler.AppendDataToFile(@"C:\Users\Public\TestFolder\Buglist.txt", "The AppPoolIdentitytype \"SpecificUser\" is NOT correctly set for " + applicationPool.Name + ". The currently set value is \"" + applicationPool.ProcessModel.IdentityType.ToString() + "\"");
            return;
        }
        else
        {
            OutputHandler.ColorCMDOutput("The AppPoolIdentitytype \"SpecificUser\" is correctly set for " + applicationPool.Name, ConsoleColor.Green);
        }
        {
            if (applicationPool.ProcessModel.UserName != ServiceUser)
            {
                OutputHandler.ColorCMDOutput("The AppPoolUserame \"Administrator\" is NOT correctly set  for " + applicationPool.Name + ". The currently set value is \"" + applicationPool.ProcessModel.UserName.ToString() + "\"", ConsoleColor.Red);
                OutputHandler.AppendDataToFile(@"C:\Users\Public\TestFolder\Buglist.txt", "The AppPoolUserame \"Administrator\" is NOT correctly set  for " + applicationPool.Name + ". The currently set value is \"" + applicationPool.ProcessModel.UserName.ToString() + "\"");
            }
            else
            {
                OutputHandler.ColorCMDOutput("The AppPoolUserame \"Administrator\" is correctly set for " + applicationPool.Name, ConsoleColor.Green);
            }            if (applicationPool.ProcessModel.Password != ServiceUserPassword)
            {
                OutputHandler.ColorCMDOutput("The AppPoolPassword \"admin\" is NOT correctly set  for " + applicationPool.Name + ". The currently set value is \"" + applicationPool.ProcessModel.Password.ToString() + "\"", ConsoleColor.Red);
                OutputHandler.AppendDataToFile(@"C:\Users\Public\TestFolder\Buglist.txt", "The AppPoolPassword \"admin\" is NOT correctly set  for " + applicationPool.Name + ". The currently set value is \"" + applicationPool.ProcessModel.Password.ToString() + "\"");
            }
            else
            {
                OutputHandler.ColorCMDOutput("The AppPoolPassword \"admin\" is correctly set for " + applicationPool.Name, ConsoleColor.Green);
            }
        }
    }    private void CheckApplicationPoolStartMode(ApplicationPool applicationPool)
    {    }
}

}

1 ответ

Есть решение
Lex Li ответил: 31 июля 2018 в 11:02

Используйте .Attributes класса ConfigurationElement (класс Application является производным от него) для доступа к такому

https:// msdn .microsoft.com / EN-US / библиотека / microsoft.web.administration.configurationelement.attributes (v = VS.90) .aspx

fabian09 ответил: 03 августа 2018 в 10:38
Это сработало отлично. Спасибо.