【发布时间】:2012-09-11 19:34:35
【问题描述】:
我收到了这个错误
访问被拒绝。 (来自 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
请帮忙>????
【问题讨论】:
-
什么用户运行你的代码?拒绝访问是一个安全问题,这意味着还要检查外部因素。
-
什么用户运行你的代码是什么意思?我现在可以知道这个用户吗?
-
您的代码...所有代码...在某个特定用户帐户的支持下运行,并且仅具有该帐户提供的安全授权。我想知道它是否在与您预期不同的用户帐户下运行。
-
我向您寻求帮助,但我仍然不知道如何获取该用户并授予他权限。
-
搜索应用池的标识
标签: asp.net vb.net iis directoryentry