public WebConnectionGroup (ServicePoint sPoint, string name) { this.sPoint = sPoint; this.name = name; connections = new LinkedList<ConnectionState> (); queue = new Queue<HttpWebRequest> (); }
public bool CheckValidationResult( ServicePoint srvPoint , X509Certificate certificate , WebRequest request , int certificateProblem) { //Return True to force the certificate to be accepted. return true; }
public override void OnActionExecuting(ActionExecutingContext filterContext) { using (ServicePoint services = new ServicePoint()) { bool anyAuthory = services.AdminUser.IsAuthory(_menuId, CurrentUser.Id); if (!anyAuthory) { RouteValueDictionary routing = new RouteValueDictionary { { "action", "AuthoryError" }, { "controller", "AdminError" } }; filterContext.Result = new RedirectToRouteResult(routing); } } base.OnActionExecuting(filterContext); }
public ServicePoint Parse() { var servicePoint = new ServicePoint() { HandlingOffice = handlingOffice, Name = name, RouteDistance = routeDistance, RoutingCode = routingCode, Id = servicePointId }; if (visitingAddress != null) servicePoint.VisitingAddress = visitingAddress.Parse(); if (deliveryAddress != null) servicePoint.DeliveryAddress = deliveryAddress.Parse(); if (openingHours != null) servicePoint.OpeningHours = openingHours.Select(h => h.Parse()); return servicePoint; }
public Connection(ServicePoint servicePoint) { _state = 0; _servicePoint = servicePoint; _saea = SaeaPool.Default.GetSaea(); _buffer = BufferPool.Default.GetBuffer(); _socket = new Socket(servicePoint.HostEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); _socket.NoDelay = !servicePoint.UseNagleAlgorithm; if (_servicePoint.IsSecured) { _asyncReadWrite = new SslAsyncReadWrite(servicePoint.Address.Host, _socket, _saea, servicePoint.ClientCertificate, ValidateServerCertificate); } else { _asyncReadWrite = new AsyncReadWrite(_socket, _saea); } }
internal static bool IdleServicePointTimeout(ServicePoint servicePoint) { Lazy<ServicePoint> idleServicePoint = null; if (_servicePoints.TryRemove(servicePoint.LookupString, out idleServicePoint)) { return true; } return false; }
public bool CheckValidationResult( ServicePoint service_point, X509Certificate cert, WebRequest web_request, int certificate_problem) { // Always accept return true; }
internal async Task SetResponseDataAsync(WebConnectionData data) { var isLocked = false; var closeStream = default(Stream); try { Monitor.Enter(_locker, ref isLocked); if (Aborted) { closeStream = data.Stream; return; } _previousWebResponse = _webResponse; WebException wexc = null; try { var createTask = HttpWebResponse.CreateAsync(Address, _method, data, CookieContainer); if (createTask.IsCompleted) _webResponse = createTask.Result; else { try { Monitor.Exit(_locker); isLocked = false; _webResponse = await createTask.ConfigureAwait(false); } finally { Monitor.Enter(_locker, ref isLocked); } } } catch (Exception e) { wexc = new WebException(e.Message, e, WebExceptionStatus.ProtocolError, null); closeStream = data.Stream; } if (wexc == null && (_method == "POST" || _method == "PUT")) { await CheckSendErrorAsync(data).ConfigureAwait(false); if (_savedExc != null) wexc = (WebException)_savedExc; } } finally { if (isLocked) Monitor.Exit(_locker); if (null != closeStream) closeStream.Close(); } isLocked = false; try { Monitor.TryEnter(_locker, ref isLocked); if (Aborted) { if (data.Stream != null) data.Stream.Close(); return; } WebException wexc = null; var r = _asyncRead; var forced = false; if (r == null && _webResponse != null) { // This is a forced completion (302, 204)... forced = true; r = new TaskCompletionSource<HttpWebResponse>(); r.TrySetResult(_webResponse); } if (r != null) { if (wexc != null) { _haveResponse = true; if (!r.Task.IsCompleted) r.TrySetException(wexc); return; } var isProxy = ProxyQuery && !_proxy.IsBypassed(Address); try { var redirected = await CheckFinalStatusAsync().ConfigureAwait(false); if (!redirected) { if ((isProxy ? _proxyAuthState.IsNtlmAuthenticated : _authState.IsNtlmAuthenticated) && _webResponse != null && (int)_webResponse.StatusCode < 400) { var wce = _webResponse.GetResponseStream() as WebConnectionStream; if (wce != null) { var cnc = wce.Connection; cnc.NtlmAuthenticated = true; } } // clear internal buffer so that it does not // hold possible big buffer (bug #397627) if (_writeStream != null) _writeStream.KillBuffer(); _haveResponse = true; r.TrySetResult(_webResponse); } else { if (_webResponse != null) { if (await HandleNtlmAuthAsync(r.Task).ConfigureAwait(false)) return; _webResponse.Close(); } FinishedReading = false; _haveResponse = false; _webResponse = null; //r.Reset(); _servicePoint = GetServicePoint(); _abortHandler = _servicePoint.SendRequest(this, _connectionGroup); } } catch (WebException wexc2) { if (forced) { _savedExc = wexc2; _haveResponse = true; } r.TrySetException(wexc2); } catch (Exception ex) { wexc = new WebException(ex.Message, ex, WebExceptionStatus.ProtocolError, null); if (forced) { _savedExc = wexc; _haveResponse = true; } r.TrySetException(wexc); } } } finally { if (isLocked) Monitor.Exit(_locker); } }
// Methods internal ServicePoint GetServicePoint() { lock (_locker) { if (_hostChanged || _servicePoint == null) { _servicePoint = ServicePointManager.FindServicePoint(Address, _proxy); _hostChanged = false; } } return _servicePoint; }
public bool CheckValidationResult(ServicePoint sPoint, X509Certificate cert, WebRequest wRequest, int certProb) { // Always accept return true; }
void GetResponseAsyncCB2(TaskCompletionSource<HttpWebResponse> aread) { if (_haveResponse) { var saved = _savedExc; if (_webResponse != null) { Monitor.Exit(_locker); if (saved == null) aread.TrySetResult(_webResponse); else aread.TrySetException(saved); return; } if (saved != null) { Monitor.Exit(_locker); aread.TrySetException(saved); return; } } if (!_requestSent) { _requestSent = true; _redirects = 0; _servicePoint = GetServicePoint(); _abortHandler = _servicePoint.SendRequest(this, _connectionGroup); } Monitor.Exit(_locker); }
public bool CheckValidationResult (ServicePoint sp, X509Certificate certificate, WebRequest request, int error) { // whatever the reason we do not stop the SSL connection return true; }
private ServicePoint FindServicePoint(bool forceFind) { var servicePoint = _servicePoint; if (servicePoint == null || forceFind) { lock (this) { if (_servicePoint == null || forceFind) { _servicePoint = ServicePointManager.FindServicePoint(_uri, _proxy); } servicePoint = _servicePoint; } } return servicePoint; }
public bool CheckValidationResult (ServicePoint point, X509Certificate certificate, WebRequest request, int certificateProblem) { return true; }
public bool CheckValidationResult(ServicePoint sp, System.Security.Cryptography.X509Certificates.X509Certificate cert, WebRequest req, int problem) { return true; }
internal PolicyWrapper(ICertificatePolicy policy, ServicePoint sp, WebRequest wr) { this.fwdPolicy = policy; srvPoint = sp; request = wr; }
public bool CheckValidationResult(ServicePoint sp, X509Certificate cert, WebRequest request, int problem) { return problem == (int)CertificateProblem.OK; }
public bool CheckValidationResult(ServicePoint sp, X509Certificate cert, WebRequest req, int problem) { return true; }
public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) { // you can do your own certificate checking here // you can get the error values from WinError.h, all the certificate errors start with Cert_ /* if(unchecked((int)(0x800B0109L)) == certificateProblem) //A certificate chain processed correctly, but terminated in a root certificate which is not trusted by the trust provider. { return true; } */ // we just return true so any certificate will work with this sample return true; }
public LayoutController() { Service = new ServicePoint(); }
public bool CheckValidationResult(ServicePoint sPoint, System.Security.Cryptography.X509Certificates.X509Certificate cert, WebRequest wRequest, int certProb) { // Always accept return true; }
public AdminLayoutController() { Services = new ServicePoint(); }
// ignoring certificate errors public bool CheckValidationResult(ServicePoint sp, X509Certificate certificate, WebRequest request, int error) { return true; }
public override Task<Stream> GetRequestStreamAsync(CancellationToken cancellationToken) { if (Aborted) throw new WebException("The request was canceled.", WebExceptionStatus.RequestCanceled); var send = !(_method == "GET" || _method == "CONNECT" || _method == "HEAD" || _method == "TRACE"); if (_method == null || !send) throw new ProtocolViolationException("Cannot send data when method is: " + _method); if (_contentLength == -1 && !_sendChunked && !AllowWriteStreamBuffering && KeepAlive) throw new ProtocolViolationException("Content-Length not set"); var transferEncoding = TransferEncoding; if (!_sendChunked && transferEncoding != null && transferEncoding.Trim() != "") throw new ProtocolViolationException("SendChunked should be true."); lock (_locker) { if (_getResponseCalled) throw new InvalidOperationException("The operation cannot be performed once the request has been submitted."); if (isBusy) { throw new InvalidOperationException("Cannot re-call start of asynchronous " + "method while a previous call is still in progress."); } _initialMethod = _method; if (null != _asyncWrite) return _asyncWrite.Task; //if (haveRequest) //{ // if (writeStream != null) // return writeStream; //} _gotRequestStream = true; _asyncWrite = new TaskCompletionSource<Stream>(); if (!_requestSent) { _requestSent = true; _redirects = 0; _servicePoint = GetServicePoint(); _abortHandler = _servicePoint.SendRequest(this, _connectionGroup); } return _asyncWrite.Task; } }
public bool CheckValidationResult (ServicePoint sp, X509Certificate certificate, WebRequest request, int error) { if (error != 0) { Console.WriteLine (certificate.ToString (true)); // X509Certificate.ToString(true) doesn't show dates :-( Console.WriteLine ("\tValid From: {0}", certificate.GetEffectiveDateString ()); Console.WriteLine ("\tValid Until: {0}{1}", certificate.GetExpirationDateString (), Environment.NewLine); ShowCertificateError (error); } // whatever the reason we do not stop the SSL connection return true; }
/// <summary> /// 通过设置这个属性,可以在发出连接的时候绑定客户端发出连接所使用的IP地址。 /// </summary> /// <param name="servicePoint"></param> /// <param name="remoteEndPoint"></param> /// <param name="retryCount"></param> /// <returns></returns> private IPEndPoint BindIPEndPointCallback(ServicePoint servicePoint, IPEndPoint remoteEndPoint, int retryCount) { return(_IPEndPoint);//端口号 }