【发布时间】:2012-06-20 05:37:08
【问题描述】:
我正在开发适用于 Intranet 环境的 ASP.NET 4.0 MVC3 Web 应用程序。该应用程序使用 Windows 身份验证。它的应用程序池由在域控制器上设置了 spn 的域用户运行。使用 Kerberos 进行身份验证(经过一些额外配置后在 IE 和 Firefox 上)。
现在我想将文件上传到 sharepoint,但在用户当前登录到应用程序时上传文件对我来说很重要(因此文件是使用他/她的凭据在 Sharepoint 上创建的)。
我在ResourceExists(Uri uri)函数中有如下代码:
'...
Dim identity As System.Security.Principal.WindowsIdentity = HttpContext.User.Identity
Dim impersonationContext = identity.Impersonate()
response = request.GetResponse()
impersonationContext.Undo()
'...
这在本地运行时有效,但是当我部署到服务器时出现异常:
System.Net.WebException: The remote server returned an error: (401) Unauthorized.\r\n at WebDav.WebDavClient.ResourceExists(Uri uri)\r\n at Website.Website.WebdavController.Upload(HttpPostedFileBase file, UploadViewModel vm)
我读到了一些关于传递凭据的信息,这在 NTLM 中是不可能的,但我确定我使用的是 Kerberos(我使用 wireshark 和 fiddler 检查了标头)并且我看到了以下内容:
Authorization: Negotiate YIIFpQYGKwYBBQUCoIIFmTCCBZWgJDAiBgkqhkiC9x...
任何想法为什么在 IIS 服务器上运行时模拟不起作用?
【问题讨论】:
标签: asp.net-mvc-3 .net-4.0 windows-authentication impersonation kerberos