Why can't I get Site.State for an FTP site when using Microsoft.Web.Administration?

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 by which I could see the above error 0x800710D8 COM? I can manage the FTP site simply using the IIS Manager (I can start, stop, change settings, etc.).

+6
c # iis
source share
2 answers

The first thing to clarify is that Site.State is a property to get the status of the HTTP protocol, and for this reason I assume that the site that throws this exception is probably NOT an HTTP site.

If you want to get FTP status, you need to do the following:

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

You can check if the site is HTTP or not by checking Site.Bindings and looking for the protocol property, if it does not have HTTP or HTTPS, you will get an exception that you can safely ignore.

For more information: FTP Settings / IIS.net Code Example

+5
source share

I think the answer is that this is just a bug in the Microsoft IIS API that we need to live with. I opened an error report in MS connect, which had 2 upvotes, however MS did not show any interest in this (and I doubt that they will be soon).

I do not believe that there is a way around the actual state (as the question asks). Some of them suggested that I should investigate port 21, but this only speaks of starting the FTP server, and not which FTP server is working (since you can have several sites) - therefore, in some cases this approach is completely useless .

The workaround to stop and start the site (which also causes a similar error) is to set auto-start to false on the FTP site and restart IIS (this is not very convenient, but everything works fine).

+1
source share

All Articles