Change Virtual Directory Property

J

Just D.

How can we change the property of one subdirectory of the Virtual Directory?
One of the directories should be granted "Write".

Should we delete this Virtual Directory to recreate it with the required
property or there is some way to do that? What I see now is a poor
documentation on the Internet about that.

Thanks,
Just D.
 
E

Erik Funkenbusch

How can we change the property of one subdirectory of the Virtual Directory?
One of the directories should be granted "Write".

Should we delete this Virtual Directory to recreate it with the required
property or there is some way to do that? What I see now is a poor
documentation on the Internet about that.

Unless i'm missing something more about what you are referring to, what's
wrong with just right clicking on the virtual directory in IIS Manager and
choosing properties, going to the Home Directory tab and clicking "write"?

That seems about as obvious as you can get.
 
J

Just D.

There is only one thing wrong - it must be the tool written in C#. The tool
itself is done, but there is one small trouble remaining in it. That's what
I'm asking about.

Just D.
 
M

Marc Scheuner

How can we change the property of one subdirectory of the Virtual Directory?
One of the directories should be granted "Write".

You can use ADSI to examine and set properties on a virtual directory.
The relevant classes live in the System.DirectoryServices namespace -
you'll need to add a reference to that assembly to your C# project.

If you already have a virtual directory and you just want to change
some setting, proceed as follows:

1) Bind to the virtual directory ("MyDir" for this sample) - you need
to know the web server name ("MyServer" for this sample), and the web
number (usually 0):

DirectoryEntry deVDir = new
DirectoryEntry("IIS://MyServer/W3SVC/0/Root/MyDir");

2) If the bind succeeded, you should be able to access the properties
of the VDir through the DirectoryEntry:

if(deVDir != null)
{
string sPhysicalDir = deVDir.Properties["Path"][0].ToString();
}

3) There is a large number of properties on the VDir - those of
interest to you will be AccessRead, AccessWrite, AccessScript,
AccessExecute and AccessSource. Those are of type boolean, and from
what I see, you need to put a value of "0" in them for false, -1 for
true.

You can modify these properties like this:

deVDir.Properties["AccessWrite"].Value = -1;

and then you need to persist the changes

deVDir.CommitChanges();

That should allow you to "save" your existing VDir and set the
properties according to your needs.

For more info on System.DirectoryServices, see the S.DS portal at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sds/sds/portal.asp

Unfortunately, the chapter on "Using System.DirectoryServices to
Configure IIS" is still missing after all those months.....

Cheers!
Marc
 
J

Just D.

Hi Marc,

Thanks for this answer. I tested it on my machine but it actually didn't
help. In some cases the VS shows that the methods or properties are
returning the NonImplemented exceptions. Maybe it's because I'm working with
the VS2003 and .NET 1.1, not 2.0.

Using the method that you described I was able to get the virtual directory
of the whole application as well as the subdirectory using the whole Virtual
Path to this directory, and get the property of the first one, but I could
not get the property of the subdirectory since it was an NonImplemented
exception. Very strange! It works somehow in the system, maybe I should use
anything else to grant a required permission.

Btw, you mentioned that the MSDN keeps silence, maybe it's because the
feature is not implemented?

Just D.

Marc Scheuner said:
How can we change the property of one subdirectory of the Virtual
Directory?
One of the directories should be granted "Write".

You can use ADSI to examine and set properties on a virtual directory.
The relevant classes live in the System.DirectoryServices namespace -
you'll need to add a reference to that assembly to your C# project.

If you already have a virtual directory and you just want to change
some setting, proceed as follows:

1) Bind to the virtual directory ("MyDir" for this sample) - you need
to know the web server name ("MyServer" for this sample), and the web
number (usually 0):

DirectoryEntry deVDir = new
DirectoryEntry("IIS://MyServer/W3SVC/0/Root/MyDir");

2) If the bind succeeded, you should be able to access the properties
of the VDir through the DirectoryEntry:

if(deVDir != null)
{
string sPhysicalDir = deVDir.Properties["Path"][0].ToString();
}

3) There is a large number of properties on the VDir - those of
interest to you will be AccessRead, AccessWrite, AccessScript,
AccessExecute and AccessSource. Those are of type boolean, and from
what I see, you need to put a value of "0" in them for false, -1 for
true.

You can modify these properties like this:

deVDir.Properties["AccessWrite"].Value = -1;

and then you need to persist the changes

deVDir.CommitChanges();

That should allow you to "save" your existing VDir and set the
properties according to your needs.

For more info on System.DirectoryServices, see the S.DS portal at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sds/sds/portal.asp

Unfortunately, the chapter on "Using System.DirectoryServices to
Configure IIS" is still missing after all those months.....

Cheers!
Marc
 

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

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top