something wrong with my use of System.DirectoryServices

S

Stephanie Stowe

Hi. I am trying to read information out of the IIS metabase (v5.1). Observe
the following code:

using System;
using System.DirectoryServices;
using System.Reflection;

namespace ADSI1
{
class ConfigIIS
{
[STAThread]
static void Main(string[] args)
{
string serverName = "localhost";
string password = "Y@ms,M0s";


DirectoryEntry site = new DirectoryEntry
("IIS://localhost/W3SVC/1/Root/Stowesoft", "localhost\\administrator",
password, AuthenticationTypes.Secure);


Console.WriteLine ( site.Path );
Console.WriteLine();

foreach ( string propName in site.Properties.PropertyNames)
{
Console.WriteLine(propName);
foreach (object value in site.Properties[propName])
{
Console.WriteLine("\tname = " + propName + ", value = "
+ value);
}
}

Console.WriteLine("Done");

}
}
}

At foreach(string propName in site.Properties.ProerptyNames)

I receive the runtime error

An unhandled exception of type 'System.NotSupportedException' occurred in
system.directoryservices.dll

Additional information: The directory cannot report the number of
properties.

I do not NEED to iterate through the properties so much as check the values
of the properties that I want. My underlying goal is to compare the IIS
setup on a production server to the known desired values. So I want to be
able to read the IIS metabase for virtual root. So for a given virtual root,
what are the application settings, what is the local path, authentication
information...

I don't know how to find out these property names. So I either

- need to learn what is wrong with my code for iterating through the
properties OR
- need to know the name of the properties (from some documentation I could
not find that perhaps one could point me to) available so that I can get the
values directly.

Thanks for your help!

Stephanie
 
W

Willy Denoyette [MVP]

Running following on W2K3 (IIS6):
{
DirectoryEntry de = new DirectoryEntry("IIS://scenic/W3SVC/1/root",
"administrator", "pwd",
AuthenticationTypes.Secure);

foreach( string myKey in de.Properties.PropertyNames)
{
Console.WriteLine(myKey + " " + de.Properties[myKey].Value);
}
}

dumps :
AccessFlags 513
AccessSSLFlags 0
AppIsolated 2
AuthFlags 5
FrontPageWeb True
AppFriendlyName Default Application
AppPoolId DefaultAppPool
AppRoot /LM/W3SVC/1/ROOT
KeyType IIsWebVirtualDir
Path d:\inetpub\wwwroot
HttpCustomHeaders System.Object[]
ScriptMaps System.Object[]
DefaultDoc Default.htm,Default.asp,index.htm,iisstart.htm,Default.aspx
AppAllowClientDebug False
AppAllowDebugging False
AspAllowOutOfProcComponents True
AspAllowSessionState True
AspAppServiceFlags 0
AspBufferingLimit 4194304
AspBufferingOn True
AspCalcLineNumber True
AspCodepage 0
AspEnableApplicationRestart True
AspEnableAspHtmlFallback False
AspEnableChunkedEncoding True
AspEnableParentPaths False
AspEnableTypelibCache True
AspErrorsToNTLog False
AspExceptionCatchEnable True
AspExecuteInMTA 0
AspKeepSessionIDSecure 0
AspLCID 2048
AspLogErrorRequests True
AspMaxDiskTemplateCacheFiles 2000
AspMaxRequestEntityAllowed 204800
AspProcessorThreadMax 25
AspQueueConnectionTestTime 3
AspQueueTimeout -1
AspRequestQueueMax 3000
AspRunOnEndAnonymously True
AspScriptEngineCacheMax 250
AspScriptErrorSentToBrowser True
AspScriptFileCacheSize 500
AspScriptTimeout 90
AspSessionMax -1
AspSessionTimeout 20
AspTrackThreadingModel False
BITSAllowOverwrites 0
BITSHostIdFallbackTimeout 86400
BITSServerNotificationType 0
BITSSessionTimeout 1209600
CGITimeout 300
ContentIndexed True
DirBrowseFlags 1073741886
PasswordChangeFlags 6
AnonymousUserName IUSR_SCENIC
AnonymousUserPass %Z33<cyw@;8*Rt
AspScriptErrorMessage An error occurred on the server when processing the
URL.
Please contact the system administrator.
AspScriptLanguage VBScript
AuthChangeURL /iisadmpwd/achg.asp
AuthExpiredUnsecureURL /iisadmpwd/aexp3.asp
AuthExpiredURL /iisadmpwd/aexp.asp
AuthNotifyPwdExpUnsecureURL /iisadmpwd/anot3.asp
AuthNotifyPwdExpURL /iisadmpwd/anot.asp
BITSHostId
BITSMaximumUploadSize 18446744073709551615
BITSServerNotificationURL
BITSSessionDirectory BITS-Sessions
HttpExpires D, 0x15180
AdminACL System.__ComObject
AspDiskTemplateCacheDirectory %windir%\system32\inetsrv\ASP Compiled
Templates
HttpErrors System.Object[]

Willy.


Stephanie Stowe said:
Hi. I am trying to read information out of the IIS metabase (v5.1).
Observe
the following code:

using System;
using System.DirectoryServices;
using System.Reflection;

namespace ADSI1
{
class ConfigIIS
{
[STAThread]
static void Main(string[] args)
{
string serverName = "localhost";
string password = "Y@ms,M0s";


DirectoryEntry site = new DirectoryEntry
("IIS://localhost/W3SVC/1/Root/Stowesoft", "localhost\\administrator",
password, AuthenticationTypes.Secure);


Console.WriteLine ( site.Path );
Console.WriteLine();

foreach ( string propName in site.Properties.PropertyNames)
{
Console.WriteLine(propName);
foreach (object value in site.Properties[propName])
{
Console.WriteLine("\tname = " + propName + ", value = "
+ value);
}
}

Console.WriteLine("Done");

}
}
}

At foreach(string propName in site.Properties.ProerptyNames)

I receive the runtime error

An unhandled exception of type 'System.NotSupportedException' occurred in
system.directoryservices.dll

Additional information: The directory cannot report the number of
properties.

I do not NEED to iterate through the properties so much as check the
values
of the properties that I want. My underlying goal is to compare the IIS
setup on a production server to the known desired values. So I want to be
able to read the IIS metabase for virtual root. So for a given virtual
root,
what are the application settings, what is the local path, authentication
information...

I don't know how to find out these property names. So I either

- need to learn what is wrong with my code for iterating through the
properties OR
- need to know the name of the properties (from some documentation I could
not find that perhaps one could point me to) available so that I can get
the
values directly.

Thanks for your help!

Stephanie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top