以编程方式从IIS获取站点状态,返回COM错误 [英] Programmatically get site status from IIS, gets back COM error

查看:230
本文介绍了以编程方式从IIS获取站点状态,返回COM错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以编程方式从IIS获取我的站点状态以查看它是否已停止,但我一直收到以下错误,

I am trying to programmatically get my site status from IIS to see if it's stopped, but I kept getting the following error,


对象标识符不代表有效对象。 (来自HRESULT的异常:0x800710D8)

The object identifier does not represent a valid object. (Exception from HRESULT: 0x800710D8)

应用程序正在使用ServerManager Site类来访问站点状态。这是代码,

The application is using ServerManager Site class to access the site status. Here is the code,

//This is fine, gets back the site 
var serverManager = new Microsoft.Web.Administration.ServerManager(ConfigPath);
var site = serverManager.Sites.FirstOrDefault(x => x.Id == 5);
if (site == null) return;
var appPoolName = site.Applications["/"].ApplicationPoolName;
//error!
var state = site.State;

我使用静态网站测试以隔离问题,确保网站已启动并运行,所有配置都有效,指向有效的应用程序池...等。

I've test with static site to isolate the issue, making sure that the site is up and running, all configuration are valid, point to the valid application pool...etc.

如果您需要更多详细信息,请告诉我。这是COM的事吗?

Let me know if you need more details. Is it the COM thing?

推荐答案

我找出了问题所在。基本上,服务器管理器有两个部分,服务器管理器的第一部分允许您从配置文件中读取站点详细信息,这就是我上面所做的。问题是你只能获得文件和站点状态不属于它的信息。

I figured out where the problem is. Basically, there are two parts to the Server manager, the first part of the server manager allows you to read site details from configuration file, which is what I've been doing above. The problem with that is you will only able get the information that's in file and site state is not part of it.

服务器管理器的第二部分允许你连接直接到IIS,它通过与COM元素交互来完成。所以我应该这样做:

The second part of the Server Manager allows you to connect to the IIS directly and it does this by interacting with the COM element. So what I should be doing is this:

ServerManager manager= ServerManager.OpenRemote("testserver");
var site = manager.Sites.First();
var status = site.State.ToString() ;

这篇关于以编程方式从IIS获取站点状态,返回COM错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆