【发布时间】:2018-11-16 11:00:13
【问题描述】:
环境:IIS 7.5、Windows 7 Pro、Visual Studio 2012、Webapp 使用 Framework 4.0
我尝试通过网络服务 (asmx) 使用 \\server\share\directory 等路径从文件服务器获取目录列表。
我在 web.config 中使用如下配置:
<identity impersonate="true" />
<authentication mode="Windows" />
我检查 User.Identity.Name 和 Threading.Thread.CurrentPrincipal.Identity.Name 并获取用于登录的域\用户名。如果我尝试获取“\\server\share\directory”的目录列表,则会引发“System.UnauthorizedAccessException”。
我尝试了很多方法,甚至使用本地系统、本地服务或域管理员作为应用程序池的身份。
当我将配置 system.webServer/serverRuntime authenticatedUserOverride 从 UseAuthenticatedUser 更改为 UseWorkerProcessUser 时,我可以访问网络共享,但以应用程序池用户的身份而不是使用 Web 服务的用户身份。在此配置中,我无法获取有关已使用登录名的信息,而是始终以应用程序池的用户身份获取。
是否可以在不模拟的情况下获得 windows-login-user ? 或者必须做什么才能成功访问网络文件系统?
我认为我的机器上的 UAC 已禁用。
【问题讨论】:
-
\server\share\directory 是您的问题中的拼写错误,还是您在代码的开头使用了单个反斜杠?需要两个反斜杠 \\server\share\directory。您确定您同时拥有目录本身和共享安全的访问权限吗?检查 CurrentPrincipal 应确保您的模拟按预期工作。
-
对不起!双反斜杠显示为单反斜杠。我编辑帖子。
-
网络共享通常作为网络驱动器(例如 K:\, I:) 映射到“模拟”用户,当他登录到他的工作站时。所以我认为访问权限应该没问题。
-
查看System.Security.Principal.WindowsIdentity.GetCurrent.Name的值,这是我之前使用的方法。 ApplicationPool 设置可能有问题。尝试使用 AdvancedSettings/ProcessModel/Identity 和 LoadUserProfile 字段。
标签: vb.net exception iis windows-7 impersonation