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

            bool needs_reset           = false;
            NetworkCredential cnc_cred = cnc.NtlmCredential;

            bool              isProxy    = (request.Proxy != null && !request.Proxy.IsBypassed(request.RequestUri));
            ICredentials      req_icreds = (!isProxy) ? request.Credentials : request.Proxy.Credentials;
            NetworkCredential req_cred   = (req_icreds != null) ? req_icreds.GetCredential(request.RequestUri, "NTLM") : null;

            if (cnc_cred == null || req_cred == null || cnc_cred.Domain != req_cred.Domain || cnc_cred.UserName != req_cred.UserName ||
                cnc_cred.Password != req_cred.Password)
            {
                needs_reset = true;
            }

            if (!needs_reset)
            {
                bool req_sharing = request.UnsafeAuthenticatedConnectionSharing;
                bool cnc_sharing = cnc.UnsafeAuthenticatedConnectionSharing;
                needs_reset = (req_sharing == false || req_sharing != cnc_sharing);
            }
            if (needs_reset)
            {
                cnc.Close(false);                  // closes the authenticated connection
                cnc.ResetNtlm();
            }
        }
Ejemplo n.º 2
0
 public override void Dispose()
 {
     if (connection != null)
     {
         connection.Close(false);
     }
 }
Ejemplo n.º 3
0
        public override int Read(byte[] buffer, int offset, int size)
        {
            AsyncCallback  cb  = cb_wrapper;
            WebAsyncResult res = (WebAsyncResult)BeginRead(buffer, offset, size, cb, null);

            if (!res.IsCompleted && !res.WaitUntilComplete(ReadTimeout, false))
            {
                nextReadCalled = true;
                cnc.Close(true);
                throw new WebException("The operation has timed out.", WebExceptionStatus.Timeout);
            }

            return(EndRead(res));
        }