一个关于IIS的类

原创 2004年02月13日 11:28:00

Imports System<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

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("



Welcome to  "

+ webSiteName + "")

            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

IIS与Apache同时使用80端口

将apache设为使用80端口,IIS使用其它端口,比如81,然后将apache作为IIS的代理。速度有影响. 在httpd.conf里面,取消下面四行的注释: LoadModule proxy_...
  • soarheaven
  • soarheaven
  • 2015年12月15日 15:27
  • 941

IIS的完整控制类(转贴,我做了部分修改和补充)

using System;using System.Data;using System.DirectoryServices;using System.Collections;namespace Cre...
  • wenzhoufeng
  • wenzhoufeng
  • 2007年04月28日 16:50
  • 554

关于 IIS 的一个报错

  上次机房分配了一台新电脑, 装的是XP 的系统;我在上面装了iis 5.1 然后在上面运行下,发现老是报“Microsoft JET Database Engine (0x80004005)操作必...
  • fx397993401
  • fx397993401
  • 2010年01月02日 23:28
  • 239

一个IIS下多个站点的方法

C:\Windows\System32\Drivers\Etc目录下的hosts文件主要用于域名解释。 校园网上不了天涯论坛了?有个猛人给了个好方法:他说:我前段时间也上不去。就给天涯发了个邮件...
  • llns1
  • llns1
  • 2012年05月18日 09:47
  • 1928

c++ 实现Student类

创建一个Student类,包含学生姓名,学号,性别,年龄,三科成绩,平均成绩等数据成员,在该类中定义成员函数实现相关信息的输入,输出。#include #include using namespace...
  • TimEckel
  • TimEckel
  • 2017年04月21日 11:06
  • 607

"创建控件时出错/lm/w3svc/... 不是一个有效的iis应用程序" 的解决办法

  环境:vs2005,asp.net web 应用程序(项目),IIS作为发布服务器导致原因:是项目的属性配置中,“服务器”的设置中与IIS中的虚拟目录不一致导致。 解决办法:按项目属性的中的“服务...
  • xjbx
  • xjbx
  • 2007年12月13日 10:24
  • 2502

asp.net,IIS控制管理类(c#)(一)

using System;using System.DirectoryServices;namespace Com.Net{ ///  /// IISUtil 的摘要说明。 ///**********...
  • linuxyz85
  • linuxyz85
  • 2007年05月02日 12:20
  • 422

【作业】用c++定义一个student类

定义一个student类,包含数据成员Num、Name、Birthday、Chinese、Maths、English、Total, 其中总成绩是个成绩之和。写出完整的类定义,并在主函数中实现对类的调用...
  • zhangzm0128
  • zhangzm0128
  • 2016年09月25日 17:44
  • 550

创建控件时出错/lm/w3svc/... 不是一个有效的iis应用程序" 的解决办法

环境:vs2005,asp.net web 应用程序(项目),IIS作为发布服务器 导致原因:是项目的属性配置中,“服务器”的设置中与IIS中的虚拟目录不一致导致。 解决办法:按项目属性的中的“服...
  • E_wsq
  • E_wsq
  • 2008年11月13日 03:40
  • 1377

Java设计person类,有姓名,年龄,性别。要求:该类至多只能创建一男,一女两个对象。

课后习题 Java设计person类,有姓名,年龄,性别。要求:该类至多只能创建一男,一女两个对象。 package com.liuyanzhao; class Person { privat...
  • LIU_YANZHAO
  • LIU_YANZHAO
  • 2017年05月22日 14:55
  • 585
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:一个关于IIS的类
举报原因:
原因补充:

(最多只允许输入30个字)