|
You can create virtual directories in IIS
using .NET. Sample Vb.net code is pasted below please
contact me for any further information to use it.
|
0001 Imports System
0002 Imports System.DirectoryServices
0003
0004
0005 Public Class IISManager
0006 Public Sub IISManager()
0007 End Sub
0008
0009
0010 Public Function CreateVDir(ByVal NewsiteName As String, ByVal Path As String, ByVal chkRead As Boolean, ByVal chkWrite As Boolean, ByVal chkExecute As Boolean, ByVal chkScript As Boolean, ByVal chkAuth As Boolean, ByVal serverName As String, ByVal DefaultDoc As String, ByVal dirList() As String) As Boolean
0011
0012 Dim sRet As String = String.Empty
0013 Dim IISSchema As System.DirectoryServices.DirectoryEntry
0014 Dim IISAdmin As System.DirectoryServices.DirectoryEntry
0015 Dim VDir As System.DirectoryServices.DirectoryEntry
0016 Dim IISUnderNT As Boolean
0017
0018
0019
0020 IISSchema = New System.DirectoryServices.DirectoryEntry("IIS://" + serverName + "/Schema/AppIsolated")
0021 If (IISSchema.Properties("Syntax").Value.ToString().ToUpper() = "BOOLEAN") Then
0022 IISUnderNT = True
0023 Else
0024 IISUnderNT = False
0025 End If
0026
0027
0028 IISSchema.Dispose()
0029
0030
0031
0032 Dim root As DirectoryEntry = New DirectoryEntry("IIS://" & serverName & "/W3SVC")
0033
0034
0035 Dim siteID As Integer = 1
0036
0037
0038 For Each e As DirectoryEntry In root.Children
0039 If e.SchemaClassName = "IIsWebServer" Then
0040 Dim ID As Integer = Convert.ToInt32(e.Name)
0041 If (ID >= siteID) Then
0042 siteID = ID + 1
0043 End If
0044 End If
0045 Next
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066 siteID = 312010922
0067
0068
0069
0070
0071
0072 IISAdmin = New System.DirectoryServices.DirectoryEntry("IIS://" + serverName + "/W3SVC/" + siteID.ToString() + "/Root")
0073
0074
0075
0076
0077
0078 For Each v As System.DirectoryServices.DirectoryEntry In IISAdmin.Children()
0079
0080 exists()
0081 Try
0082 IISAdmin.Invoke("Delete", New String() {v.SchemaClassName, v.Name})
0083 IISAdmin.CommitChanges()
0084 Catch ex As Exception
0085 End Try
0086 Next
0087
0088
0089
0090
0091
0092 Dim ii As Integer = 0
0093
0094
0095 For ii = 0 To dirList.Length - 1
0096 Dim dirName = dirList(ii).Split("")(dirList(ii).Split("").Length - 1).ToUpper()
0097 If Not (dirName.toupper() = "BIN" Or dirName.toupper() = "BLL") Then
0098 Try
0099 VDir = IISAdmin.Children.Add(dirName, "IIsWebVirtualDir")
0100
0101
0102
0103 VDir.Properties("AccessRead")(0) = chkRead
0104 VDir.Properties("AccessExecute")(0) = chkExecute
0105 VDir.Properties("AccessWrite")(0) = chkWrite
0106 VDir.Properties("AccessScript")(0) = chkScript
0107 VDir.Properties("AuthNTLM")(0) = chkAuth
0108 VDir.Properties("EnableDefaultDoc")(0) = True
0109 VDir.Properties("EnableDirBrowsing")(0) = False
0110 VDir.Properties("DefaultDoc")(0) = True
0111 VDir.Properties("Path")(0) = Path
0112
0113
0114
0115
0116 If (IISUnderNT = False) Then
0117 VDir.Properties("AspEnableParentPaths")(0) = True
0118 End If
0119
0120
0121
0122
0123
0124 VDir.CommitChanges()
0125 VDir.Invoke("Put", "DefaultDoc", DefaultDoc)
0126 VDir.Invoke("SetInfo")
0127
0128
0129
0130 If (IISUnderNT = True) Then
0131 VDir.Invoke("AppCreate", False)
0132 Else
0133 VDir.Invoke("AppCreate", 1)
0134 End If
0135 Catch ex As Exception
0136
0137
0138 End Try
0139 End If
0140 Next
0141
0142
0143 Return True
0144 End Function
0145
0146
0147 Public Property ServerName() As String
0148 Get
0149 Return _serverName
0150 End Get
0151 Set(ByVal Value As String)
0152 _serverName = Value
0153 End Set
0154 End Property
0155
0156
0157 Public Shared VirDirSchemaName As String = "IIsWebVirtualDir"
0158 Private _serverName As String
0159
0160
0161 End Class
|
|
|
|
|