对于HttpWebRequest.Credentials建设CredentialCache时重定向是UKNOWN重定向、Credentials、HttpWebRequest、UKNOWN

2023-09-04 00:50:56 作者:屌姐 o┤*`□′ *├o

最近,我问了一个question有关的NetworkCredential和HttpWebRequest.Credentials当服务器返回的重定向。我决定建立的NetworkCredential实例的CredentialCache适用于我的方案。现在我有一个建立与所有的域名硬$ C $光盘CredentialCache在临时的方法,它的工作,这是伟大的。

I recently asked a question concerning NetworkCredential and HttpWebRequest.Credentials when a server returns redirects. I determined that building a CredentialCache of NetworkCredential instances works for my scenario. Now I have a temporary method that builds a CredentialCache with all of the domain names hard coded in. It worked, which is great.

        CredentialCache cache = new CredentialCache();
        cache.Add(new Uri("http://example.com"), "Negotiate", loginCredentials);
        cache.Add(new Uri("http://redirected.example.com"), "Negotiate", loginCredentials);
        request.Credentials = cache;

现在,我需要让这种更灵活。该重定向的整体思路是在服务器上的负载均衡。客户端将不知道它的确切位置会被重定向到直到调用HttpWebRequest.GetResponse()。什么是preferred方法来构建CredentialCache包括每个重定向服务器,因为他们遇到过吗?此外,什么是理性的背后使这个这么难吗?为什么不能单一NetworkCredentials实例满足HttpWebRequest.Credentials每个重定向?是否引入安全漏洞,在重定向重用凭据?

Now, I need to make this more flexible. The whole idea of the redirects is for load balancing on the server. The client won't know exactly where it'll get redirected to until the call to HttpWebRequest.GetResponse(). What is the preferred method to building the CredentialCache to include each redirected server as they are encountered? Also, what is the rational behind making this so difficult? Why can't a single NetworkCredentials instance satisfy HttpWebRequest.Credentials for each redirect? Does it introduce security vulnerabilities to reuse credentials across redirects?

感谢。

推荐答案

我用code和得到401错误(SharePoint 2010的OOB的Web服务)。然后,在其他一些网站上确认并尝试过,而不是 NTLM 协商在下面的线。现在它的正常工作。

I used the code and got 401 error (SharePoint 2010 OOB Web Services). Then checked in some other site and tried "NTLM" instead of "Negotiate" in the below line. It's working fine now.

不工作:

cache.Add(New Uri(myProxy.Url), "Negotiate", New NetworkCredential("UserName", "Password", "Domain"))

工作:

cache.Add(New Uri(myProxy.Url), "NTLM", New NetworkCredential("UserName", "Password", "Domain"))