1. 论坛系统升级为Xenforo,欢迎大家测试!
    排除公告

VB.net创建虚拟目录后写入权限怎样得到

本帖由 Brosnan2005-09-03 发布。版面名称:后端开发

  1. Brosnan

    Brosnan New Member

    注册:
    2005-09-03
    帖子:
    1,032
    赞:
    9
    VB.net创建虚拟目录后写入权限怎样得到

    Imports System
    Imports System.DirectoryServices
    Imports System.IO

    Public Class test
    Inherits System.Web.UI.Page

    #Region " Web 窗体设计器生成的代码 "

    '该调用是 Web 窗体设计器所必需的。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Me.DirectoryEntry1 = New System.DirectoryServices.DirectoryEntry

    End Sub
    Protected WithEvents LinkButton1 As System.Web.UI.WebControls.LinkButton
    Protected WithEvents DirectoryEntry1 As System.DirectoryServices.DirectoryEntry
    Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button

    '注意: 以下占位符声明是 Web 窗体设计器所必需的。
    '不要删除或移动它。
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
    '不要使用代码编辑器修改它。
    InitializeComponent()
    End Sub

    #End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    '在此处放置初始化页的用户代码
    CriaDiretorioVirtual("sltt1", "1", "./Root", False)
    End Sub

    Function CriaDiretorioVirtual(ByVal vdirname As String, ByVal serverID As String, ByVal vdirPath As String, ByVal criaApplication As Boolean) As DirectoryEntry
    Dim newvdir As System.DirectoryServices.DirectoryEntry
    Dim root As DirectoryEntry
    root = New DirectoryEntry("IIS://localhost/W3SVC/" + serverID + "/Root")
    newvdir = root.Children.Add(vdirname, "IIsWebVirtualDir")
    newvdir.Properties("Path")(0) = vdirPath
    If criaApplication Then
    newvdir.Invoke("AppCreate", True)
    newvdir.Properties("AppFriendlyName")(0) = vdirname
    newvdir.Properties("AppIsolated")(0) = 2
    End If
    newvdir.CommitChanges()
    Return newvdir
    End Function
    End Class