System.Net.WebConnectionGroup.PrepareSharingNtlm C# (CSharp) Method

PrepareSharingNtlm() static private method

static private PrepareSharingNtlm ( WebConnection cnc, HttpWebRequest request ) : void
cnc WebConnection
request HttpWebRequest
return void
		static void PrepareSharingNtlm (WebConnection cnc, HttpWebRequest request)
		{
			if (!cnc.NtlmAuthenticated)
				return;

			bool needs_reset = false;
			NetworkCredential cnc_cred = cnc.NtlmCredential;
			NetworkCredential req_cred = request.Credentials.GetCredential (request.RequestUri, "NTLM");
			if (cnc_cred.Domain != req_cred.Domain || cnc_cred.UserName != req_cred.UserName ||
				cnc_cred.Password != req_cred.Password) {
				needs_reset = true;
			}
#if NET_1_1
			if (!needs_reset) {
				bool req_sharing = request.UnsafeAuthenticatedConnectionSharing;
				bool cnc_sharing = cnc.UnsafeAuthenticatedConnectionSharing;
				needs_reset = (req_sharing == false || req_sharing != cnc_sharing);
			}
#endif
			if (needs_reset) {
				cnc.Close (false); // closes the authenticated connection
				cnc.ResetNtlm ();
			}
		}

Usage Example

Example #1
0
        private WebConnection CreateOrReuseConnection(HttpWebRequest request)
        {
            int           num = this.connections.Count;
            WebConnection webConnection;

            for (int i = 0; i < num; i++)
            {
                WeakReference weakReference = this.connections[i] as WeakReference;
                webConnection = (weakReference.Target as WebConnection);
                if (webConnection == null)
                {
                    this.connections.RemoveAt(i);
                    num--;
                    i--;
                }
                else if (!webConnection.Busy)
                {
                    WebConnectionGroup.PrepareSharingNtlm(webConnection, request);
                    return(webConnection);
                }
            }
            if (this.sPoint.ConnectionLimit > num)
            {
                webConnection = new WebConnection(this, this.sPoint);
                this.connections.Add(new WeakReference(webConnection));
                return(webConnection);
            }
            if (this.rnd == null)
            {
                this.rnd = new Random();
            }
            int           index          = (num <= 1) ? 0 : this.rnd.Next(0, num - 1);
            WeakReference weakReference2 = (WeakReference)this.connections[index];

            webConnection = (weakReference2.Target as WebConnection);
            if (webConnection == null)
            {
                webConnection = new WebConnection(this, this.sPoint);
                this.connections.RemoveAt(index);
                this.connections.Add(new WeakReference(webConnection));
            }
            return(webConnection);
        }