Home All Groups Group Topic Archive Search About

Set a anonymous access in virtual directory through VB.NET

Author
22 May 2006 5:51 AM
Rose winsle
Hi guys ...

I just wanted to create virtual directory using VB.net . i can manage that
... when i create the virtual directory how can i set anonymous access off.

following is my code
==============

      Dim IISSchema As New System.DirectoryServices.DirectoryEntry("IIS://"
& WebSite & "/Schema/AppIsolated")
        Dim CanCreate As Boolean = Not
IISSchema.Properties("Syntax").Value.ToString.ToUpper() = "BOOLEAN"
        IISSchema.Dispose()

        If CanCreate Then
            Dim PathCreated As Boolean

            Try
                Dim IISAdmin As New
System.DirectoryServices.DirectoryEntry("IIS://" & WebSite &
"/W3SVC/1/Root")

                'make sure folder exists
                If Not System.IO.Directory.Exists(Path) Then
                    System.IO.Directory.CreateDirectory(Path)
                    PathCreated = True
                End If

                'If the virtual directory already exists then delete it
                For Each VD As System.DirectoryServices.DirectoryEntry In
IISAdmin.Children
                    If VD.Name = AppName Then
                        'IISAdmin.Invoke("Delete", New String()
{VD.SchemaClassName, AppName})
                        'IISAdmin.CommitChanges()
                        MsgBox("Virtual directory already exists..!.",
MsgBoxStyle.Information, "Create Virtual Directory")
                        Exit Sub
                    End If
                Next VD

                'Create and setup new virtual directory
                Dim VDir As System.DirectoryServices.DirectoryEntry =
IISAdmin.Children.Add(AppName, "IIsWebVirtualDir")
                VDir.Properties("Path").Item(0) = Path
                VDir.Properties("AppFriendlyName").Item(0) = AppName
                VDir.Properties("EnableDirBrowsing").Item(0) = False
                VDir.Properties("AccessRead").Item(0) = True
                VDir.Properties("AccessExecute").Item(0) = False '
                VDir.Properties("AccessWrite").Item(0) = False
                VDir.Properties("AccessScript").Item(0) = True
                VDir.Properties("AuthNTLM").Item(0) = False 'Integreted
Windows Authontocation
                VDir.Properties("EnableDefaultDoc").Item(0) = True
                VDir.Properties("DefaultDoc").Item(0) =
"default.aspx,default.htm,default.asp"
                VDir.Properties("AspEnableParentPaths").Item(0) = True

                VDir.CommitChanges()

                VDir.Invoke("AppCreate", 1)


So can you please tell me how to set Anonymous access OFF.

-Rosy



- R

Author
22 May 2006 7:33 PM
vbnetdev
..Properties("AuthAnonymous")(0) = False

--
Get a powerful web, database, application, and email hosting with KJM
Solutions
http://www.kjmsolutions.com



Show quoteHide quote
"Rose winsle" <chana***@solutionsit.com.au> wrote in message
news:esieYPWfGHA.4276@TK2MSFTNGP03.phx.gbl...
> Hi guys ...
>
> I just wanted to create virtual directory using VB.net . i can manage that
> .. when i create the virtual directory how can i set anonymous access off.
>
> following is my code
> ==============
>
>      Dim IISSchema As New System.DirectoryServices.DirectoryEntry("IIS://"
> & WebSite & "/Schema/AppIsolated")
>        Dim CanCreate As Boolean = Not
> IISSchema.Properties("Syntax").Value.ToString.ToUpper() = "BOOLEAN"
>        IISSchema.Dispose()
>
>        If CanCreate Then
>            Dim PathCreated As Boolean
>
>            Try
>                Dim IISAdmin As New
> System.DirectoryServices.DirectoryEntry("IIS://" & WebSite &
> "/W3SVC/1/Root")
>
>                'make sure folder exists
>                If Not System.IO.Directory.Exists(Path) Then
>                    System.IO.Directory.CreateDirectory(Path)
>                    PathCreated = True
>                End If
>
>                'If the virtual directory already exists then delete it
>                For Each VD As System.DirectoryServices.DirectoryEntry In
> IISAdmin.Children
>                    If VD.Name = AppName Then
>                        'IISAdmin.Invoke("Delete", New String()
> {VD.SchemaClassName, AppName})
>                        'IISAdmin.CommitChanges()
>                        MsgBox("Virtual directory already exists..!.",
> MsgBoxStyle.Information, "Create Virtual Directory")
>                        Exit Sub
>                    End If
>                Next VD
>
>                'Create and setup new virtual directory
>                Dim VDir As System.DirectoryServices.DirectoryEntry =
> IISAdmin.Children.Add(AppName, "IIsWebVirtualDir")
>                VDir.Properties("Path").Item(0) = Path
>                VDir.Properties("AppFriendlyName").Item(0) = AppName
>                VDir.Properties("EnableDirBrowsing").Item(0) = False
>                VDir.Properties("AccessRead").Item(0) = True
>                VDir.Properties("AccessExecute").Item(0) = False '
>                VDir.Properties("AccessWrite").Item(0) = False
>                VDir.Properties("AccessScript").Item(0) = True
>                VDir.Properties("AuthNTLM").Item(0) = False 'Integreted
> Windows Authontocation
>                VDir.Properties("EnableDefaultDoc").Item(0) = True
>                VDir.Properties("DefaultDoc").Item(0) =
> "default.aspx,default.htm,default.asp"
>                VDir.Properties("AspEnableParentPaths").Item(0) = True
>
>                VDir.CommitChanges()
>
>                VDir.Invoke("AppCreate", 1)
>
>
> So can you please tell me how to set Anonymous access OFF.
>
> -Rosy
>
>
>
> - R
>
Author
23 May 2006 1:27 AM
Rose winsle
Hi vbnetdev,

Thanks for the reply .. but i tried this. it gives me follwing error

"Index was out of range.Must be non-negative and less than the size of
collection, parameter name :Index"

pls help me

-Rose

Show quoteHide quote
"vbnetdev" <vbnetdev@community.nospam> wrote in message
news:%23K0WVadfGHA.1324@TK2MSFTNGP04.phx.gbl...
> .Properties("AuthAnonymous")(0) = False
>
> --
> Get a powerful web, database, application, and email hosting with KJM
> Solutions
> http://www.kjmsolutions.com
>
>
>
> "Rose winsle" <chana***@solutionsit.com.au> wrote in message
> news:esieYPWfGHA.4276@TK2MSFTNGP03.phx.gbl...
>> Hi guys ...
>>
>> I just wanted to create virtual directory using VB.net . i can manage
>> that .. when i create the virtual directory how can i set anonymous
>> access off.
>>
>> following is my code
>> ==============
>>
>>      Dim IISSchema As New
>> System.DirectoryServices.DirectoryEntry("IIS://" & WebSite &
>> "/Schema/AppIsolated")
>>        Dim CanCreate As Boolean = Not
>> IISSchema.Properties("Syntax").Value.ToString.ToUpper() = "BOOLEAN"
>>        IISSchema.Dispose()
>>
>>        If CanCreate Then
>>            Dim PathCreated As Boolean
>>
>>            Try
>>                Dim IISAdmin As New
>> System.DirectoryServices.DirectoryEntry("IIS://" & WebSite &
>> "/W3SVC/1/Root")
>>
>>                'make sure folder exists
>>                If Not System.IO.Directory.Exists(Path) Then
>>                    System.IO.Directory.CreateDirectory(Path)
>>                    PathCreated = True
>>                End If
>>
>>                'If the virtual directory already exists then delete it
>>                For Each VD As System.DirectoryServices.DirectoryEntry In
>> IISAdmin.Children
>>                    If VD.Name = AppName Then
>>                        'IISAdmin.Invoke("Delete", New String()
>> {VD.SchemaClassName, AppName})
>>                        'IISAdmin.CommitChanges()
>>                        MsgBox("Virtual directory already exists..!.",
>> MsgBoxStyle.Information, "Create Virtual Directory")
>>                        Exit Sub
>>                    End If
>>                Next VD
>>
>>                'Create and setup new virtual directory
>>                Dim VDir As System.DirectoryServices.DirectoryEntry =
>> IISAdmin.Children.Add(AppName, "IIsWebVirtualDir")
>>                VDir.Properties("Path").Item(0) = Path
>>                VDir.Properties("AppFriendlyName").Item(0) = AppName
>>                VDir.Properties("EnableDirBrowsing").Item(0) = False
>>                VDir.Properties("AccessRead").Item(0) = True
>>                VDir.Properties("AccessExecute").Item(0) = False '
>>                VDir.Properties("AccessWrite").Item(0) = False
>>                VDir.Properties("AccessScript").Item(0) = True
>>                VDir.Properties("AuthNTLM").Item(0) = False 'Integreted
>> Windows Authontocation
>>                VDir.Properties("EnableDefaultDoc").Item(0) = True
>>                VDir.Properties("DefaultDoc").Item(0) =
>> "default.aspx,default.htm,default.asp"
>>                VDir.Properties("AspEnableParentPaths").Item(0) = True
>>
>>                VDir.CommitChanges()
>>
>>                VDir.Invoke("AppCreate", 1)
>>
>>
>> So can you please tell me how to set Anonymous access OFF.
>>
>> -Rosy
>>
>>
>>
>> - R
>>
>
>