我正在尝试在WinForms应用程序中使用System.Net.WebClient上传文件到一个仅支持Windows身份验证的IIS6服务器。
WebClient myWebClient = new WebClient();
myWebClient.Credentials = new System.Net.NetworkCredential(@"boxname\peter", "mypassword");
byte[] responseArray = myWebClient.UploadFile("http://localhost/upload.aspx", fileName);
我收到了一个“远程服务器返回错误:(401)未经授权”的错误,实际上是401.2。
客户端和IIS都在同一台Windows Server 2003开发机上。
当我尝试在Firefox中打开页面并输入与代码中相同的正确凭据时,页面会出现。 然而,在使用IE8时,我收到了相同的401.2错误。
尝试使用Chrome和Opera它们都能正常工作。
在IE Internet选项中,我已启用“启用集成Windows身份验证”。
安全事件日志有一个失败的审核:
Logon Failure:
Reason: An error occurred during logon
User Name: peter
Domain: boxname
Logon Type: 3
Logon Process: ÈùÄ
Authentication Package: NTLM
Workstation Name: boxname
Status code: 0xC000006D
Substatus code: 0x0
Caller User Name: -
Caller Domain: -
Caller Logon ID: -
Caller Process ID: -
Transited Services: -
Source Network Address: 127.0.0.1
Source Port: 1476
我使用了 Process Monitor 和 Fiddler 进行调查,但是没有发现任何问题。
为什么这对第三方浏览器有效,但对 IE 或 System.Net.WebClient 无效?