Home All Groups Group Topic Archive Search About

How to grant and deny the access to a virtual directory?

Author
7 Jul 2006 2:10 PM
Maurizio Poletto
Hi

I have created a virtual directory on IIS using  a method in
System.Enterprise.Service:

//      create application virtual directory
IISVirtualRoot virtualDir = new IISVirtualRoot();
virtualDir.Delete("IIS://localhost/W3SVC/" + siteId + "/ROOT", physicalPath,
virtualPath, out error);

Now I need to grant or deny programmatically the access to this virtual dir
(c#) to some  Ip Addresses.
Can someone suggest how to do this ?

Best regards

Author
10 Jul 2006 1:27 PM
Nicole Calinoiu
"Maurizio Poletto" <MaurizioPole***@discussions.microsoft.com> wrote in
message news:87D9DEF4-7CD4-4CB5-961B-C37D9D373CB8@microsoft.com...
> Hi
>
> I have created a virtual directory on IIS using  a method in
> System.Enterprise.Service:

Actually, IISVirtualRoot is in the System.EnterpriseServices.Internal
namespace, which should be a good indicator to check the documentation,
where you will find this useful nugget: "This class supports the .NET
Framework infrastructure and is not intended to be used directly from your
code."  Besides this issue, the class provides very minimal functionality
and isn't particularly useful for what you want to do.


> //      create application virtual directory
> IISVirtualRoot virtualDir = new IISVirtualRoot();
> virtualDir.Delete("IIS://localhost/W3SVC/" + siteId + "/ROOT",
> physicalPath,
> virtualPath, out error);

Wouldn't the Create method be a better choice than the Delete method?


> Now I need to grant or deny programmatically the access to this virtual
> dir
> (c#) to some  Ip Addresses.
> Can someone suggest how to do this ?

IISVirtualRoot creates virtual directories by using functionality exposed in
the System.DirectoryServices namespace.
http://www.15seconds.com/issue/010710.htm provides a reasonable introduction
to this technique, and there are more details available at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/html/d39fae66-abe7-4902-a3fc-f36151561f01.asp.
You may also wish to grab a copy of Reflector
(http://www.aisto.com/roeder/dotnet/) to see exactly what IISVirtualRoot
does.

To restrict access to an existing virtual directory to a set of IP
addresses, you'll need to manipulate the IPSecurity metabase property.
There's an MSDN topic on this at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/html/0608ec6c-4bf5-42bd-a5f5-db2de1d96584.asp,
but it would seem that the sample code is missing.  However, there is a
sample at http://www.codeproject.com/csharp/iiswmi.asp that you may find
useful.