2012-09-19 62 views
0

,當我得到這個錯誤訪問被拒絕創建虛擬目錄

訪問被拒絕。 (異常來自HRESULT:0X80070005 (E_ACCESSDENIED))

當我嘗試使用帶有asp.net web表單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 

任何幫助請>>

+0

什麼用戶運行你的代碼?拒絕訪問是一個安全問題,也意味着檢查外部因素。 –

+0

你是什麼意思關於什麼用戶運行你的代碼?知道我可以現在這個用戶? –

+1

您的代碼...所有代碼...都在某些特定用戶帳戶的支持下運行,並且只有安全授權才能提供該帳戶。我想知道它是否在不同的用戶帳戶下運行比您預期的。 –

回答

1

如果您正在運行由Visual Studio應用程序,啓動Visual Studio爲管理員

如果您是通過IIS運行,設置您的用戶以管理員身份那些對所需的權限的用戶應用程序池
打開IIS /去應用程序池/右鍵單擊您的應用程序池/高級設置/過程模型/加載用戶配置=真/
點擊身份,並選擇您的帳戶

好運

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 

解決方案讓我的問題得到解決::在鏈接中完成上述所有內容之後。

我必須這樣做也解決拒絕訪問錯誤==>以管理員批准模式中管理員的所有==>禁用..