简体   繁体   English

使用Microsoft.Web.Administration时,为什么我无法获取FTP站点的Site.State?

[英]Why am I unable to get Site.State for an FTP site, when using Microsoft.Web.Administration?

Using the following C# code: 使用以下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

Any ideas why I might be seeing the above 0x800710D8 COM error? 任何想法,为什么我可能会看到上面的0x800710D8 COM错误? I'm able to manage the FTP site just fine using IIS manager (I can start, stop, change settings, etc). 我能够使用IIS管理器管理FTP站点(我可以启动,停止,更改设置等)。

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. 要澄清的第一件事是Site.State是获取HTTP协议状态的属性,因此我的猜测是抛出该异常的站点可能不是HTTP站点。

If you want to get the FTP state you need to do is: 如果你想获得FTP状态,你需要做的是:

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

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. 您可以通过检查Site.Bindings并查找Protocol属性来验证站点是否为HTTP,如果它没有HTTP或HTTPS,您将获得上面可以安全忽略的异常。

For more information: IIS.net FTP Settings / Sample Code 有关更多信息: IIS.net FTP设置/示例代码

I think the answer is that this is just a bug in the Microsoft IIS API that we have to live with. 我认为答案是,这只是我们必须使用的Microsoft IIS API中的一个错误。 I've opened a bug report on MS connect which has had 2 upvotes, however MS have shown no interest in this (and I doubt they will any time soon). 我已经打开了关于MS连接的错误报告,该报告有2个upvotes,但MS对此没有兴趣(我怀疑他们会很快)。

I don't believe there is a workaround for getting the actual state (as the question asks). 我不相信有一个解决方法来获得实际状态(正如问题所示)。 Some have suggested that I should probe port 21, but this only tells me if there is an FTP server running, not what FTP server is running (as you can have multiple sites) -- so in some cases, this approach is completely useless. 有些人认为我应该探索端口21,但这只是告诉我,如果有一个 FTP服务器上运行,运行FTP服务器不是 (你可以有多个站点) -因此,在某些情况下,这种做法是完全无用的。

The workaround to stopping and starting the site (which also causes a similar error) is to set auto-start to false on the FTP site and restart IIS (it's not great, but it works just fine). 停止和启动站点的解决方法(也会导致类似的错误)是在FTP站点上将auto-start设置为false并重新启动IIS(它不是很好,但它工作得很好)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Microsoft.Web.Administration将ISAPI筛选器添加到现有站点 - Add an ISAPI Filter to an existing Site with Microsoft.Web.Administration 尝试将应用程序添加到站点时,Microsoft.Web.Administration空引用 - Microsoft.Web.Administration null reference when trying to add application to site 为什么尝试从Microsoft.Web.Administration连接ServerManager时出现COMException? - Why Am I getting COMException while trying to connect ServerManager from Microsoft.Web.Administration? 使用Microsoft.Web.Administration以编程方式在IIS7中创建远程站点:索引无效。 (来自HRESULT的异常:0x80070585) - Programmatically creating a remote site in IIS7 using Microsoft.Web.Administration: Invalid index. (Exception from HRESULT: 0x80070585) 使用 Microsoft.Web.Administration 应用程序更改身份验证模式 - Using Microsoft.Web.Administration Application to change authentication mode 使用Microsoft.Web.Administration设置ASP设置 - Setting up ASP settings using Microsoft.Web.Administration 添加https绑定时,Microsoft.Web.Administration中的NullReferenceException - NullReferenceException in Microsoft.Web.Administration when adding https binding 如何使用Microsoft.Web.Administration添加子应用程序? - How to add child application using Microsoft.Web.Administration? 使用 Microsoft.Web.Administration 以编程方式安装 SSL 证书 - Install SSL certificate programmatically using Microsoft.Web.Administration 如何使用Microsoft.Web.Administration命名空间在IIS7中干净地操作Handler Mappings? - How do I manipulate Handler Mappings cleanly in IIS7 using the Microsoft.Web.Administration namespace?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM