为什么我无法得到Site.State一个FTP站点,使用Microsoft.Web.Administration什么时候? [英] Why am I unable to get Site.State for an FTP site, when using Microsoft.Web.Administration?

查看:563
本文介绍了为什么我无法得到Site.State一个FTP站点,使用Microsoft.Web.Administration什么时候?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用下面的C#代码:

using System;
using Microsoft.Web.Administration;

namespace getftpstate
{
  class Program
  {
    static void Main(string[] args)
    {
      ServerManager manager = new ServerManager();
      foreach (Site site in manager.Sites)
      {
        Console.WriteLine("name: " + site.Name);
        Console.WriteLine("state: " + site.State);
        Console.WriteLine("----");
      }
    }
  }
}



我得到下面的输出:

I get the following output:

C:\projects\testiisftp\getftpstate\getftpstate\bin\Debug>getftpstate.exe
name: Default Web Site
state: Stopped
----
name: Default FTP Site

Unhandled Exception: System.Runtime.InteropServices.COMException (0x800710D8): T
he object identifier does not represent a valid object. (Exception from HRESULT:
 0x800710D8)
   at Microsoft.Web.Administration.Interop.IAppHostProperty.get_Value()
   at Microsoft.Web.Administration.ConfigurationElement.GetPropertyValue(IAppHos
tProperty property)
   at Microsoft.Web.Administration.Site.get_State()
   at getftpstate.Program.Main(String[] args) in C:\projects\testiisftp\getftpst
ate\getftpstate\Program.cs:line 17

任何想法,为什么我可能会上面看到0x800710D8 COM错误?我能够管理FTP站点就好使用IIS管理器(我可以启动,停止,更改设置等)。

Any ideas why I might be seeing the above 0x800710D8 COM error? I'm able to manage the FTP site just fine using IIS manager (I can start, stop, change settings, etc).

推荐答案

澄清的第一件事是, Site.State 是一个属性来获取HTTP协议的状态,为此,我的猜测是,该抛出该网站。例外的是可能不是一个HTTP站点

The first thing to clarify is that Site.State is a property to get the state of the HTTP protocol and for that reason my guess is that the site that is throwing that exception is probably NOT an HTTP site.

如果你想获得你需要做的FTP状态是:

If you want to get the FTP state you need to do is:

int ftpState = Site.GetChildElement("ftpServer")["state"]

您可以验证,如果一个网站是HTTP或不通过检查Site.Bindings和寻找协议属性,如果它不具有HTTP或HTTPS您将得到上面,你可以放心地忽略例外。

You can verify if a site is HTTP or not by inspecting the Site.Bindings and looking for the Protocol property, if it does not have HTTP or HTTPS you will get the exception above which you could safely ignore.

有关信息的 IIS.net FTP设置/示例代码

这篇关于为什么我无法得到Site.State一个FTP站点,使用Microsoft.Web.Administration什么时候?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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