分享
 
 
 

一个关于IIS的类

王朝system·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

Imports System

Imports System.DirectoryServices

Imports System.IO

Public Class IISManager

Public Shared Function CreateWebSite(ByVal webSiteName As String, ByVal pathToRoot As String) As WebSite

Dim root As DirectoryEntry = New DirectoryEntry("IIS://localhost/W3SVC")

' Find unused ID value for new web site

Dim siteID As Integer = 1

Dim e As DirectoryEntry

For Each e In root.Children

If e.SchemaClassName = "IIsWebServer" Then

Dim ID As Integer = Convert.ToInt32(e.Name)

If ID >= siteID Then

siteID = ID + 1

End If

End If

Next

' Create the root directory and welcome html file

CreatePhysicalDirectory(pathToRoot, webSiteName)

' Create web site

Dim site As New WebSite(CType(root.Invoke("Create", "IIsWebServer", siteID), DirectoryEntry))

site.ServerComment = webSiteName

'site.KeyType = "IIsWebServer"

site.ServerBindings = ":80:" + webSiteName

site.MaxBandwidth = "1048576"

site.ServerState = 2

site.LogFlags.LogExtFileFlags = 340871

site.FrontPageWeb = 1

'site.DefaultDoc = "Default.aspx"

'site.SecureBindings = ":443:" + webSiteName

site.ServerAutoStart = 1

site.ServerSize = 1

site.SetInfo()

' Create application virtual directory

Dim siteVDir As DirectoryEntry = site.Children.Add("Root", "IISWebVirtualDir")

siteVDir.Properties("AppIsolated")(0) = 2

siteVDir.Properties("Path")(0) = pathToRoot

siteVDir.Properties("AccessFlags")(0) = 513

siteVDir.Properties("FrontPageWeb")(0) = 1

siteVDir.Properties("AppRoot")(0) = "/LM/W3SVC/" + siteID.ToString() + "/Root"

'siteVDir.Properties("AppFriendlyName")(0) = "Root"

siteVDir.CommitChanges()

site.CommitChanges()

siteVDir.Close()

site.Close()

' Create temp virtual directory on Default Web Site

Dim deRoot As New DirectoryEntry("IIS://localhost/W3SVC/1/Root")

deRoot.RefreshCache()

Dim deNewVDir As DirectoryEntry = deRoot.Children.Add(webSiteName.Replace("."c, "-"c), "IIsWebVirtualDir")

deNewVDir.Properties("Path")(0) = pathToRoot

deNewVDir.Properties("AccessFlags")(0) = 513

deNewVDir.Properties("FrontPageWeb")(0) = 1

deNewVDir.CommitChanges()

deRoot.CommitChanges()

'Create a Application

deNewVDir.Invoke("AppCreate", True)

'Save Changes

deNewVDir.CommitChanges()

deRoot.CommitChanges()

deNewVDir.Close()

deRoot.Close()

Return site

End Function

Private Shared Sub CreatePhysicalDirectory(ByVal pathToRoot As String, ByVal webSiteName As String)

If (Directory.Exists(pathToRoot)) Then

Throw New Exception("Error creating new website: Customer root directory already exists at " + pathToRoot)

Else

Directory.CreateDirectory(pathToRoot)

Dim indexFile As New StreamWriter(pathToRoot + "\index.htm", False, System.Text.Encoding.ASCII)

indexFile.Write("<html><body><br><br><br><br><center><h2><font name='Verdana'>Welcome to <font color='green'>&nbsp;" + webSiteName + "</font></font></h2></center></body></html>")

indexFile.Close()

End If

End Sub

End Class

Public Class WebSite

Public Sub New(ByVal ObjDirectoryEntry As DirectoryEntry)

site = ObjDirectoryEntry

logFileFlags = New LogExtFileFlags(ObjDirectoryEntry)

End Sub

Private site As DirectoryEntry

Private logFileFlags As LogExtFileFlags

Public ReadOnly Property LogFlags() As LogExtFileFlags

Get

Return logFileFlags

End Get

End Property

Public Property ServerComment() As String

Get

Return CType(site.Properties("ServerComment")(0), String)

End Get

Set(ByVal Value As String)

site.Invoke("Put", "ServerComment", Value)

End Set

End Property

Public Property KeyType() As String

Get

Return CType(site.Properties("KeyType")(0), String)

End Get

Set(ByVal Value As String)

site.Invoke("Put", "KeyType", Value)

End Set

End Property

Public Property ServerBindings() As String

Get

Return CType(site.Properties("ServerBindings")(0), String)

End Get

Set(ByVal Value As String)

site.Invoke("Put", "ServerBindings", Value)

End Set

End Property

Public Property DefaultDoc() As String

Get

Return CType(site.Properties("DefaultDoc")(0), String)

End Get

Set(ByVal Value As String)

site.Invoke("Put", "DefaultDoc", Value)

End Set

End Property

Public Property MaxBandwidth() As String

Get

Return CType(site.Properties("MaxBandwidth")(0), String)

End Get

Set(ByVal Value As String)

site.Invoke("Put", "MaxBandwidth", Value)

End Set

End Property

Public Property ServerState() As Int32

Get

Return CType(site.Properties("ServerState")(0), Int32)

End Get

Set(ByVal Value As Int32)

site.Invoke("Put", "ServerState", Value)

End Set

End Property

Public Property FrontPageWeb() As Int32

Get

Return CType(site.Properties("FrontPageWeb")(0), Int32)

End Get

Set(ByVal Value As Int32)

site.Invoke("Put", "FrontPageWeb", Value)

End Set

End Property

Public Property SecureBindings() As String

Get

Return CType(site.Properties("SecureBindings")(0), String)

End Get

Set(ByVal Value As String)

site.Invoke("Put", "SecureBindings", Value)

End Set

End Property

Public Property ServerAutoStart() As Int32

Get

Return CType(site.Properties("ServerAutoStart")(0), Int32)

End Get

Set(ByVal Value As Int32)

site.Invoke("Put", "ServerAutoStart", Value)

End Set

End Property

Public Property ServerSize() As Int32

Get

Return CType(site.Properties("ServerSize")(0), Int32)

End Get

Set(ByVal Value As Int32)

site.Invoke("Put", "ServerSize", Value)

End Set

End Property

Public ReadOnly Property Children() As DirectoryEntries

Get

Return site.Children

End Get

End Property

Public ReadOnly Property Name() As String

Get

Return site.Name

End Get

End Property

Public Sub CommitChanges()

site.CommitChanges()

End Sub

Public Sub SetInfo()

site.Invoke("SetInfo")

End Sub

Public Sub Close()

site.Close()

End Sub

End Class

Public Class LogExtFileFlags

Public Sub New(ByVal ObjDirectoryEntry As DirectoryEntry)

site = ObjDirectoryEntry

End Sub

Private site As DirectoryEntry

Public Property LogExtFileFlags() As Int32

Get

Return CType(site.Properties("LogExtFileFlags")(0), Int32)

End Get

Set(ByVal Value As Int32)

site.Invoke("Put", "LogExtFileFlags", Value)

End Set

End Property

'Public Property LogExtFileBytesRecv() As Boolean

' Get

' Return CBool(site.Properties("LogExtFileBytesRecv")(0))

' End Get

' Set(ByVal Value As Boolean)

' Dim showInLog As Int32 = 0

' If Value Then

' showInLog = 1

' End If

' site.Invoke("Put", "LogExtFileBytesRecv", showInLog)

' End Set

'End Property

End Class

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有