2

我正在尝试编写一个允许非管理员用户在 IIS6 中创建虚拟目录的应用程序。我尝试了许多不同的模拟管理帐户的方法,但似乎没有任何方法可以创建虚拟目录。

这是我尝试过的一些方法:

dim sDirPath as string = "IIS://remotehost/W3svc/1/root"
Dim de As DirectoryEntry = New DirectoryEntry()
de.Path = sDirPath
de.AuthenticationType = AuthenticationTypes.Secure
de.Username = tbxUsername.Text
de.Password = tbxPassword.Text
''Fails here
virtualId = CType(de.Invoke("Create", "IIsWebVirtualDir", dirName), DirectoryEntry)

从这里使用 AccountAlias 类:

aa.BeginImpersonation()
Try
    dim sDirPath as string = "IIS://remotehost/W3svc/1/root"
    Dim de As DirectoryEntry = New DirectoryEntry()
    de.Path = sDirPath
    de.AuthenticationType = AuthenticationTypes.Secure
    ''Fails Here
    virtualId = CType(de.Invoke("Create", "IIsWebVirtualDir", dirName), DirectoryEntry)
Finally
    aa.EndImpersonation()
End Try

在winforms应用程序中模拟另一个用户的正确方法是什么,这将允许我创建虚拟目录,而运行应用程序的用户不是Web服务器上的管理员?我知道这是可以做到的,IIS 管理器允许您使用“连接为”复选框来做到这一点。

4

1 回答 1

2

自从我遇到这个问题以来已经有很长时间了,所以我可能记错了一些事情。但是IIRC ...

IIS 的根目录受 ACL 保护,该 ACL 需要管理权限才能创建新目录。一个简单的模拟可能不会解决这个问题,因为我相信在幕后你正在组合 COM 和 RPC 或本地 RPC。跨 COM 边界的模拟在本机代码中很棘手,而在托管代码中则非常棘手。您很可能在使用您的模仿技巧时遇到了这个领域的问题。

不过可以解除对 Web 服务器的限制,让普通用户在 IIS 中创建根目录。我在以下博客文章中概述了这样做的过程

于 2010-02-02T18:32:20.920 回答