Asp.net 创建虚拟目录时拒绝访问

Asp.net 创建虚拟目录时拒绝访问,asp.net,vb.net,iis,directoryentry,Asp.net,Vb.net,Iis,Directoryentry,我犯了这个错误 访问被拒绝。(HRESULT的例外情况:0x80070005 (E_)(拒绝) 当我尝试使用vb.net代码和asp.net web窗体以及我使用的以下代码创建虚拟目录时 Private Sub CreateVirtualDir(ByVal WebSite As String, ByVal AppName As String, ByVal Path As String) Dim IISSchema As New System.DirectoryServices.

我犯了这个错误

访问被拒绝。(HRESULT的例外情况:0x80070005 (E_)(拒绝)

当我尝试使用vb.net代码和asp.net web窗体以及我使用的以下代码创建虚拟目录时

Private Sub CreateVirtualDir(ByVal WebSite As String, ByVal AppName As String, ByVal Path As String)

        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()
                        Exit For
                    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) = True
                VDir.Properties("AccessWrite").Item(0) = False
                VDir.Properties("AccessScript").Item(0) = True
                VDir.Properties("AuthNTLM").Item(0) = True
                VDir.Properties("AuthBasic").Item(0) = True
                VDir.Properties("AspBufferingOn").Item(0) = True
                VDir.Properties("EnableDefaultDoc").Item(0) = True
                VDir.Properties("DefaultDoc").Item(0) = "default.htm,default.aspx,default.asp"
                VDir.Properties("AspEnableParentPaths").Item(0) = True
                VDir.Properties("AuthAnonymous").Item(0) = True
                VDir.CommitChanges()

                'the following are acceptable params
                'INPROC = 0
                'OUTPROC = 1
                'POOLED = 2
                VDir.Invoke("AppCreate", 1)

            Catch Ex As Exception
                If PathCreated Then
                    System.IO.Directory.Delete(Path)
                End If



            End Try
        End If

    End Sub

请提供任何帮助>??

如果您是通过visual studio运行应用程序,请以管理员身份启动visual studio

如果您是通过IIS运行的,请将您的用户设置为管理员或对应用程序池具有所需权限的用户
打开IIS/转到应用程序池/右键单击应用程序池/高级设置/流程模型/加载用户配置文件=true/
单击标识并选择您的帐户


祝你好运

这个解决方案对我有效==>

此外,我这样做也解决了我的问题:

我得到的问题==>

[System.Runtime.InteropServices.COMException] {"Access is denied.\r\n"}     System.Runtime.InteropServices.COMException

ErrorCode 0x80070005
解决我的问题的解决方案::在链接中完成上述所有操作后


我还必须这样做才能解决拒绝访问错误==>在管理员批准模式下运行所有管理员==>禁用..

哪个用户运行您的代码?拒绝访问是一个安全问题,这意味着还要检查外部因素。关于哪些用户运行您的代码,您是什么意思?我现在能知道这个用户吗?你的代码。。。所有代码。。。在某些特定用户帐户的支持下运行,并且只有该帐户提供的安全授权。我想知道它是否在与您预期的不同的用户帐户下运行。我已申请您的帮助,但我仍然不知道如何获取该用户并授予其权限。搜索应用程序池的标识