![](/img/trans.png)
[英]How can I programatically determine if an IIS site is receiving requests?
[英]Programatically determine if IIS site is running or not
我有一个脚本,可收集IIS中的所有站点并通过电子邮件发送一些详细信息以进行审核。 我想对其进行调整,使其仅通过电子邮件发送正在运行的网站。 我不需要了解已停止的站点。 我已经对IIS中的所有DirectoryEntry
进行了引用,但是没有看到任何指示其是否在运行的属性。
怎么做? 理想情况下,它应同时在IIS6和IIS7上运行。
DirectoryEntry.Properties
集合包含一个ServerState
属性。 没有很好的记录,但是我发现这个博客创建了自己的枚举,似乎是正确的。 枚举是
public enum ServerState
{
Unknown = 0,
Starting = 1,
Started = 2,
Stopping = 3,
Stopped = 4,
Pausing = 5,
Paused = 6,
Continuing = 7
}
使用此逻辑检查DirectoryEntry
是否正在运行,您将使用:
DirectoryEntry entry;
ServerState state = (ServerState)Enum.Parse(typeof(ServerState), entry.Properties["ServerState"].Value.ToString())
if (state == ServerState.Stopped || state == ServerState.Paused)
{
//site is stopped
}
{
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.