我正在开发在 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 服务器上运行时不起作用吗?