2

我正在尝试使用 Microsoft.Web.Administration api“正常关闭”服务器场中的示例服务器。在互联网上找到了类似的解决方案,但它对我不起作用。

        var mgr = new ServerManager();
        var conf = mgr.GetApplicationHostConfiguration();
        var sect = conf.GetSection("webFarms");
        var webFarms = sect.GetCollection();
        var farm = webFarms[0];
        var servers = farm.GetCollection();
        var server = servers[0];

        var arr = server.GetChildElement("applicationRequestRouting");

        var counters = arr.GetChildElement("counters");
        //Console.WriteLine(counters.Attributes); // This also gives error "not supported"

        var method = arr.Methods["SetState"];
        var instance = method.CreateInstance();
        instance.Input.Attributes[0].Value = 2; //shutdown gracefully
        instance.Execute(); // Exception from HRESULT: 0x80070032
4

0 回答 0