tags:

views:

88

answers:

3

Using the following C# code:

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? I'm able to manage the FTP site just fine using IIS manager (I can start, stop, change settings, etc).

A: 

I am having this same problem and it's really put a wrench in finishing my app. I can't list sites if some are ftp sites and show status. Is this a bug somewhere when accessing ftp state?

Thanks

Mike H

Mike H
*Answers* only in the *answers* section please ;) -- you might want to move this to a comment.
nbolton
A: 

I think the answer is that this is just a bug in the Microsoft IIS API that we have to live with. 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).

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.

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).

nbolton
A: 

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.

If you want to get the FTP state you need to do is: 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.

For more information: http://www.iis.net/ConfigReference/system.applicationHost/sites/site/ftpServer

CarlosAg
Aha, interesting idea. Hmm, though I'm sure I tried accessing it in a similar way -- but I will give this a try anyway. Also I have unmarked my answer accordingly (hopefully I can delete it if you're right).
nbolton
Try it out, I do know a bit about MWA (I wrote it :) ) so let me know if it does not work, or if you run into other issue.
CarlosAg