Programmtically得到IIS站点的状态,回来COM错误 [英] Programmtically get site status from IIS, gets back COM error

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

问题描述

我试图programmtically获得IIS我的网站的状态,看看它是否停了,但我一直得到下面的错误,

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

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



应用程序使用ServerManager的站点类访问该网站的地位。下面是代码,

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() ;

这篇关于Programmtically得到IIS站点的状态,回来COM错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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