创建虚拟目录时拒绝访问

时间:2012-09-19 13:20:19

标签: asp.net vb.net iis directoryentry

我收到了这个错误

  

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

当我尝试使用带有asp.net网络表单的vb.net代码创建虚拟目录时,以下是我使用的代码..

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

任何帮助请> ????

2 个答案:

答案 0 :(得分:1)

如果您正在通过visual studio运行该应用程序,请启动visual studio作为管理员

如果您在IIS上运行,请将您的用户设置为管理员应用程序池具有所需权限的用户
打开IIS /转到应用程序池/右键单击您的应用程序池/高级设置/进程模型/加载用户配置文件= true /
点击身份并选择您的帐户

祝你好运

答案 1 :(得分:0)

此解决方案适用于我==>

http://blogs.msdn.com/b/jpsanders/archive/2009/05/13/iis-7-adsi-error-system-runtime-interopservices-comexception-0x80005000-unknown-error-0x80005000.aspx?CommentPosted=true#commentmessage ..

另外我做了这个也解决了我的问题::

问题我得到==>

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

ErrorCode 0x80070005

让我的问题得到解决的解决方案::完成链接中的所有上述内容后。

我还必须解决访问被拒绝错误==>以管理员审批模式运行所有管理员==>残疾人..