在Silverlight中使用HttpWebRequest进行Windows身份验证

时间:2014-09-15 07:10:12

标签: silverlight httpwebrequest ntlm

我在silverlight中创建了一个多上传控件(我们使用IE< 9所以我不能使用文件API)。

我正在使用:

  • Silverlight4(http客户端堆栈)
  • MVC4(Windows身份验证,DEV中的NTLM,生产中的kerberos)

我正在尝试使用当前用户凭据与用户进行身份验证,但我似乎无法可靠地进行身份验证。有时请求会通过,但大多数情况下它会因401错误而失败。

以下是代码段:

var request = (HttpWebRequest)WebRequestCreator.ClientHttp.Create(new Uri(uri));
request.AllowWriteStreamBuffering = false; // <-- this enables upload progress reporting!
request.Method = "POST";
request.ContentType = "multipart/form-data; boundary=" + temp; // Boundary only needed for multipart form ada
request.ContentLength = (Encoding.UTF8.GetByteCount(_boundary) * 2) + _file.Descriptor.Length + Encoding.UTF8.GetByteCount(_header + "--\r\n\r\n\r\n");
request.UseDefaultCredentials = true;

request.BeginGetRequestStream(new AsyncCallback(WriteToStreamCallback), request);

我禁用写入流缓冲,以便显示文件上载进度。

这是来自fiddler的auth信息。似乎它永远不会完成挑战

请求:

Authorization Header is present: NTLM
4E 54 4C 4D 53 53 50 00 01 00 00 00 07 82 08 A2  NTLMSSP.......¢
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
06 01 B1 1D 00 00 00 0F                          ..±.....        


-[NTLM Type1: Negotiation]------------------------------
Provider: NTLMSSP
Type: 1
OS Version: 6.1:7601
Flags:  0xa2088207
    Unicode supported in security buffer.
    OEM strings supported in security buffer.
    Request server's authentication realm included in Type2 reply.
    NTLM authentication.
    Negotiate Always Sign.
    Negotiate NTLM2 Key.
    Supports 56-bit encryption.
    Supports 128-bit encryption.
Domain_Offset: 0; Domain_Length: 0; Domain_Length2: 0
Host_Offset: 0; Host_Length: 0; Host_Length2: 0
Host: 
Domain: 
------------------------------------

响应:

No Proxy-Authenticate Header is present.

WWW-Authenticate Header is present: NTLM
4E 54 4C 4D 53 53 50 00 02 00 00 00 10 00 10 00  NTLMSSP.........
--truncated--            


-[NTLM Type2: Challenge]------------------------------
Provider: NTLMSSP
Type: 2
OS Version: 6.1:7601
Flags:  0xa2898205
    Unicode supported in security buffer.
    Request server's authentication realm included in Type2 reply.
    NTLM authentication.
    Negotiate Always Sign.
    Negotiate NTLM2 Key.
    Target Information block provided for use in calculation of the NTLMv2 response.
    Supports 56-bit encryption.
    Supports 128-bit encryption.
Challenge: 31 AD 21 F4 40 FF BF 75
------------------------------------

0 个答案:

没有答案
相关问题