Virtual Directory Detection #2

A

Amos Soma

Thanks to Peter Bromberg for showing me how to detect if a virtual directory
exists. Now I need to determine what folder the virtual directory points to.

For example, I have the following C# code. It correctly finds the
'MyVirtualDirectory' virtual directory. Now, what method do I call to
determine what folder 'MyVirtualDirectory' points to? I cannot seem to find
any way to do this.

DirectoryEntry virtualDirectory = new
System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/1/Root/MyVirtualDirectory");

Thanks very much.

Amos
 
C

Chris Priede

Amos said:
For example, I have the following C# code. It correctly finds the
'MyVirtualDirectory' virtual directory. Now, what method do I call to
determine what folder 'MyVirtualDirectory' points to? I cannot seem
to find any way to do this.

DirectoryEntry virtualDirectory = new
System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/1/Root/MyVirtualDirectory");

string path = virtualDirectory.Properties["Path"].Value.ToString();
 
A

Amos Soma

Chris,

This causes an 'Object reference not set to an instance of an object' error.
I don't think "Path" is a valid index into Properties.

AMos.

Chris Priede said:
Amos said:
For example, I have the following C# code. It correctly finds the
'MyVirtualDirectory' virtual directory. Now, what method do I call to
determine what folder 'MyVirtualDirectory' points to? I cannot seem
to find any way to do this.

DirectoryEntry virtualDirectory = new
System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/1/Root/MyVirtualDirectory");

string path = virtualDirectory.Properties["Path"].Value.ToString();
 
G

Guest

Amos,
Chris's code is just fine. if you are getting and object reference exception
that's because your method call to DirectoryEntry isn't returning a
DirectoryEntry object.
Check your IIS pathing.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




Amos Soma said:
Chris,

This causes an 'Object reference not set to an instance of an object' error.
I don't think "Path" is a valid index into Properties.

AMos.

Chris Priede said:
Amos said:
For example, I have the following C# code. It correctly finds the
'MyVirtualDirectory' virtual directory. Now, what method do I call to
determine what folder 'MyVirtualDirectory' points to? I cannot seem
to find any way to do this.

DirectoryEntry virtualDirectory = new
System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/1/Root/MyVirtualDirectory");

string path = virtualDirectory.Properties["Path"].Value.ToString();
 
A

Amos Soma

Peter,

I don't think Chris's code is fine, or I am doing something wrong. Here is a
test method I wrote.
This method works fine up until the 'path =
virtualDirectory.Properties["Path"].Value.ToString()' line.
It then crashes. Alos, the 'foreach' statement does not show 'Path' as being
a property of 'Properties'.

Thanks very much.
private void TestVirtualDirectory()
{

DirectoryEntry virtualDirectory = new
System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/1/Root/SDBSClientUpdate");
System.DirectoryServices.PropertyCollection collection =
virtualDirectory.Properties;
string path;

foreach(string name in collection.PropertyNames)
MessageBox.Show(
string.Format("{0}:{1}",name,virtualDirectory.Properties[name].Value.ToString())
);

path = virtualDirectory.Properties["Path"].Value.ToString();
MessageBox.Show(path);
}


Peter Bromberg said:
Amos,
Chris's code is just fine. if you are getting and object reference
exception
that's because your method call to DirectoryEntry isn't returning a
DirectoryEntry object.
Check your IIS pathing.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




Amos Soma said:
Chris,

This causes an 'Object reference not set to an instance of an object'
error.
I don't think "Path" is a valid index into Properties.

AMos.

Chris Priede said:
Amos Soma wrote:
For example, I have the following C# code. It correctly finds the
'MyVirtualDirectory' virtual directory. Now, what method do I call to
determine what folder 'MyVirtualDirectory' points to? I cannot seem
to find any way to do this.

DirectoryEntry virtualDirectory = new
System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/1/Root/MyVirtualDirectory");

string path = virtualDirectory.Properties["Path"].Value.ToString();
 
A

Amos Soma

Peter,

One thing I have learned. If the code below is run on a Windows XP
Professional box, an exception is thrown. If it's run on a Windows 2003
Server box, it works correctly.

Amos.

Amos Soma said:
Peter,

I don't think Chris's code is fine, or I am doing something wrong. Here is
a test method I wrote.
This method works fine up until the 'path =
virtualDirectory.Properties["Path"].Value.ToString()' line.
It then crashes. Alos, the 'foreach' statement does not show 'Path' as
being a property of 'Properties'.

Thanks very much.
private void TestVirtualDirectory()
{

DirectoryEntry virtualDirectory = new
System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/1/Root/SDBSClientUpdate");
System.DirectoryServices.PropertyCollection collection =
virtualDirectory.Properties;
string path;

foreach(string name in collection.PropertyNames)
MessageBox.Show(
string.Format("{0}:{1}",name,virtualDirectory.Properties[name].Value.ToString())
);

path = virtualDirectory.Properties["Path"].Value.ToString();
MessageBox.Show(path);
}


Peter Bromberg said:
Amos,
Chris's code is just fine. if you are getting and object reference
exception
that's because your method call to DirectoryEntry isn't returning a
DirectoryEntry object.
Check your IIS pathing.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




Amos Soma said:
Chris,

This causes an 'Object reference not set to an instance of an object'
error.
I don't think "Path" is a valid index into Properties.

AMos.

Amos Soma wrote:
For example, I have the following C# code. It correctly finds the
'MyVirtualDirectory' virtual directory. Now, what method do I call to
determine what folder 'MyVirtualDirectory' points to? I cannot seem
to find any way to do this.

DirectoryEntry virtualDirectory = new
System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/1/Root/MyVirtualDirectory");

string path = virtualDirectory.Properties["Path"].Value.ToString();
 
G

Guest

I ran your code doing Console.WriteLine on each line of the foreach on a
Windows XP pro machine and here's what I got:

AppIsolated: 0
AppRoot: /LM/W3SVC/1/Root/Aspose.Excel.Demos
AppFriendlyName:
KeyType: IIsWebVirtualDir
Path: C:\Program Files\Aspose\Aspose.Excel\Demos\Aspose.Excel.Demos
AccessFlags: 513
FrontPageWeb: True
AspAllowSessionState: True
AspBufferingOn: True
AspEnableParentPaths: True
AspSessionTimeout: 20
AspScriptTimeout: 90
AspScriptErrorSentToBrowser: True
CacheISAPI: True
AspLogErrorRequests: True
AspExceptionCatchEnable: True
CGITimeout: 300
AspScriptEngineCacheMax: 125
AspMaxDiskTemplateCacheFiles: 1000
AspScriptFileCacheSize: 250
AuthFlags: 5
DirBrowseFlags: 1073741824
DontLog: False
ContentIndexed: True
AppAllowDebugging: True
AppAllowClientDebug: True
AspScriptLanguage: VBScript
AspScriptErrorMessage: An error occurred on the server when processing the
URL.
Please contact the system administrator.
AspDiskTemplateCacheDirectory: C:\WINDOWS\system32\inetsrv\ASP Compiled
Template
s
DefaultDoc: default.aspx,Default.htm,Default.asp
ScriptMaps: System.Object[]
HttpErrors: System.Object[]
CPUCGIEnabled: True
CPUAppEnabled: True
AnonymousPasswordSync: True
AspTrackThreadingModel: False
AspAllowOutOfProcComponents: True
AspEnableAspHtmlFallback: False
AspEnableChunkedEncoding: True
AspEnableTypelibCache: True
AspErrorsToNTLog: False
AspProcessorThreadMax: 25
AspRequestQueueMax: 3000
AspThreadGateEnabled: False
AspThreadGateTimeSlice: 1000
AspThreadGateSleepDelay: 100
AspThreadGateSleepMax: 50
AspThreadGateLoadLow: 50
AspThreadGateLoadHigh: 80
AspQueueTimeout: -1
AspCodepage: 0
AspKeepSessionIDSecure: False
AspEnableApplicationRestart: True
AspQueueConnectionTestTime: 3
AspSessionMax: -1
AspLCID: 2048
AnonymousUserName: IUSR_xxxx
AnonymousUserPass: xxxxxxxxxxx)
Realm: xxxxxx.com
HttpCustomHeaders: X-Powered-By: ASP.NET


--Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




Amos Soma said:
Peter,

One thing I have learned. If the code below is run on a Windows XP
Professional box, an exception is thrown. If it's run on a Windows 2003
Server box, it works correctly.

Amos.

Amos Soma said:
Peter,

I don't think Chris's code is fine, or I am doing something wrong. Here is
a test method I wrote.
This method works fine up until the 'path =
virtualDirectory.Properties["Path"].Value.ToString()' line.
It then crashes. Alos, the 'foreach' statement does not show 'Path' as
being a property of 'Properties'.

Thanks very much.
private void TestVirtualDirectory()
{

DirectoryEntry virtualDirectory = new
System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/1/Root/SDBSClientUpdate");
System.DirectoryServices.PropertyCollection collection =
virtualDirectory.Properties;
string path;

foreach(string name in collection.PropertyNames)
MessageBox.Show(
string.Format("{0}:{1}",name,virtualDirectory.Properties[name].Value.ToString())
);

path = virtualDirectory.Properties["Path"].Value.ToString();
MessageBox.Show(path);
}


Peter Bromberg said:
Amos,
Chris's code is just fine. if you are getting and object reference
exception
that's because your method call to DirectoryEntry isn't returning a
DirectoryEntry object.
Check your IIS pathing.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




:

Chris,

This causes an 'Object reference not set to an instance of an object'
error.
I don't think "Path" is a valid index into Properties.

AMos.

Amos Soma wrote:
For example, I have the following C# code. It correctly finds the
'MyVirtualDirectory' virtual directory. Now, what method do I call to
determine what folder 'MyVirtualDirectory' points to? I cannot seem
to find any way to do this.

DirectoryEntry virtualDirectory = new
System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/1/Root/MyVirtualDirectory");

string path = virtualDirectory.Properties["Path"].Value.ToString();
 
C

Chris Priede

Hi,

Amos said:
One thing I have learned. If the code below is run on a Windows XP
Professional box, an exception is thrown. If it's run on a Windows 2003
Server box, it works correctly.

What is the service pack level of your XP installation?
 

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