当前位置: 首页>>代码示例>>C#>>正文


C# HttpResponseMessage.Dispose方法代码示例

本文整理汇总了C#中System.Net.Http.HttpResponseMessage.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponseMessage.Dispose方法的具体用法?C# HttpResponseMessage.Dispose怎么用?C# HttpResponseMessage.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.Http.HttpResponseMessage的用法示例。


在下文中一共展示了HttpResponseMessage.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

        private HttpResponseMessage Execute()
        {
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.Redirect);

            try
            {
                var sim = _message.Protect(600, _internalConfig.DataProtector);

                if (_loginPageUrl.IsMissing())
                {
                    var urlHelper = _request.GetUrlHelper();
                    _loginPageUrl = urlHelper.Route(Constants.RouteNames.Login, new { message = sim });
                }
                else
                {
                    _loginPageUrl += "?message=" + sim;
                }

                var uri = new Uri(_request.RequestUri, _loginPageUrl);

                response.Headers.Location = uri;
            }
            catch
            {
                response.Dispose();
                throw;
            }

            Logger.Info("Redirecting to login page");
            return response;
        }
开发者ID:nonintanon,项目名称:Thinktecture.IdentityServer.v3,代码行数:31,代码来源:LoginResult.cs

示例2: Execute

        private HttpResponseMessage Execute()
        {
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.Redirect);

            try
            {
                var protection = _settings.GetInternalProtectionSettings();
                var jwt = _message.ToJwt(
                    protection.Issuer,
                    protection.Audience,
                    protection.SigningKey,
                    protection.Ttl);

                var urlHelper = _request.GetUrlHelper();
                var loginUrl = urlHelper.Route(Constants.RouteNames.Login, new { message = jwt });
                var uri = new Uri(_request.RequestUri, loginUrl);

                response.Headers.Location = uri;
            }
            catch
            {
                response.Dispose();
                throw;
            }

            return response;
        }
开发者ID:JackBao,项目名称:Thinktecture.IdentityServer.v3,代码行数:27,代码来源:LoginResult.cs

示例3: ExecuteAsync

        public override Task<HttpResponseMessage> ExecuteAsync(CancellationToken cancellationToken)
        {
            ContentNegotiationResult result = GetContentNegotiationResult();

            HttpResponseMessage response = null;
            try
            {
                response = new HttpResponseMessage();

                if (result == null)
                {
                    //TODO: find condtions when this case can be reached
                    // A null result from content negotiation indicates that the response should be a 406.
                    response.StatusCode = HttpStatusCode.NotAcceptable;
                }
                else
                {
                    response.StatusCode = HttpStatusCode.OK;
                    response.Content = new ObjectContent<object>(new object(), result.Formatter, result.MediaType);
                }

                response.RequestMessage = Request;
            }
            catch
            {
                if (response != null)
                {
                    response.Dispose();
                }

                throw;
            }

            return Task.FromResult(response);
        }
开发者ID:WadeOne,项目名称:EasyTeach,代码行数:35,代码来源:EmptyObjectOkResult.cs

示例4: Execute

        internal static HttpResponseMessage Execute(HttpStatusCode statusCode, HttpRequestMessage request)
        {
            HttpResponseMessage response = new HttpResponseMessage(statusCode);

            try
            {
                response.RequestMessage = request;
            }
            catch
            {
                response.Dispose();
                throw;
            }

            return response;
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:16,代码来源:StatusCodeResult.cs

示例5: Execute

        private HttpResponseMessage Execute()
        {
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.Redirect);

            try
            {
                response.Headers.Location = _location;
                response.RequestMessage = _dependencies.Request;
            }
            catch
            {
                response.Dispose();
                throw;
            }

            return response;
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:17,代码来源:RedirectResult.cs

示例6: Execute

        private HttpResponseMessage Execute()
        {
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.Unauthorized);

            try
            {
                foreach (AuthenticationHeaderValue challenge in _challenges)
                {
                    response.Headers.WwwAuthenticate.Add(challenge);
                }

                response.RequestMessage = _dependencies.Request;
            }
            catch
            {
                response.Dispose();
                throw;
            }

            return response;
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:21,代码来源:UnauthorizedResult.cs

示例7: Execute

        private HttpResponseMessage Execute()
        {
            var response = new HttpResponseMessage(HttpStatusCode.Redirect);

            try
            {
                var sim = _message.Protect(600, _protector);
                var url = _env.GetIdentityServerBaseUrl() + Constants.RoutePaths.Login;
                url += "?message=" + sim;

                var uri = new Uri(url);
                response.Headers.Location = uri;
            }
            catch
            {
                response.Dispose();
                throw;
            }

            Logger.Info("Redirecting to login page");
            return response;
        }
开发者ID:JaiChaturvedi,项目名称:Thinktecture.IdentityServer.v3,代码行数:22,代码来源:LoginResult.cs

示例8: Execute

        private HttpResponseMessage Execute()
        {
            HttpResponseMessage mutableResponse = new HttpResponseMessage(_statusCode);
            HttpResponseMessage response = null;

            try
            {
                mutableResponse.RequestMessage = _dependencies.Request;

                response = mutableResponse;
                mutableResponse = null;
            }
            finally
            {
                if (mutableResponse != null)
                {
                    mutableResponse.Dispose();
                }
            }

            return response;
        }
开发者ID:samgithub-duplicate,项目名称:aspnetwebstack,代码行数:22,代码来源:StatusCodeResult.cs

示例9: Execute

        private HttpResponseMessage Execute()
        {
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.Redirect);

            try
            {
                var sim = _message.Protect(60, _internalConfig.DataProtector);

                var urlHelper = _request.GetUrlHelper();
                var loginUrl = urlHelper.Route(Constants.RouteNames.Login, new { message = sim });
                var uri = new Uri(_request.RequestUri, loginUrl);

                response.Headers.Location = uri;
            }
            catch
            {
                response.Dispose();
                throw;
            }

            return response;
        }
开发者ID:nyankov,项目名称:Thinktecture.IdentityServer.v3,代码行数:22,代码来源:LoginResult.cs

示例10: ConvertResponse

        /// <summary>
        /// Converts a <see cref="HttpResponseMessage"/> to an <see cref="HttpResponseBase"/> and disposes the 
        /// <see cref="HttpResponseMessage"/> and <see cref="HttpRequestMessage"/> upon completion.
        /// </summary>
        /// <param name="httpContextBase">The HTTP context base.</param>
        /// <param name="response">The response to convert.</param>
        /// <param name="request">The request (which will be disposed).</param>
        /// <returns>A <see cref="Task"/> representing the conversion of an <see cref="HttpResponseMessage"/> to an <see cref="HttpResponseBase"/>
        /// including writing out any entity body.</returns>
        internal static Task ConvertResponse(HttpContextBase httpContextBase, HttpResponseMessage response, HttpRequestMessage request)
        {
            Contract.Assert(httpContextBase != null);
            Contract.Assert(response != null);
            Contract.Assert(request != null);

            HttpResponseBase httpResponseBase = httpContextBase.Response;
            httpResponseBase.StatusCode = (int)response.StatusCode;
            httpResponseBase.StatusDescription = response.ReasonPhrase;
            httpResponseBase.TrySkipIisCustomErrors = true;
            EnsureSuppressFormsAuthenticationRedirect(httpContextBase);
            CopyHeaders(response.Headers, httpContextBase);
            CacheControlHeaderValue cacheControl = response.Headers.CacheControl;

            // TODO 335085: Consider this when coming up with our caching story
            if (cacheControl == null)
            {
                // DevDiv2 #332323. ASP.NET by default always emits a cache-control: private header.
                // However, we don't want requests to be cached by default.
                // If nobody set an explicit CacheControl then explicitly set to no-cache to override the
                // default behavior. This will cause the following response headers to be emitted:
                //     Cache-Control: no-cache
                //     Pragma: no-cache
                //     Expires: -1
                httpContextBase.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            }

            Task responseTask = null;
            bool isBuffered = false;

            if (response.Content != null)
            {
                CopyHeaders(response.Content.Headers, httpContextBase);

                // Select output buffering by the kind of content
                isBuffered = IsOutputBufferingNecessary(response.Content);
                httpResponseBase.BufferOutput = isBuffered;

                responseTask = response.Content.CopyToAsync(httpResponseBase.OutputStream);
            }
            else
            {
                responseTask = TaskHelpers.Completed();
            }

            return responseTask
                .Catch((info) =>
                {
                    if (isBuffered)
                    {
                        // Failure during the CopyToAsync needs to stop any partial content from
                        // reaching the client.  If it was during a buffered write, we will give
                        // them InternalServerError with zero-length content.
                        httpResponseBase.SuppressContent = true;
                        httpResponseBase.Clear();
                        httpResponseBase.ClearContent();
                        httpResponseBase.ClearHeaders();
                        httpResponseBase.StatusCode = (int)Net.HttpStatusCode.InternalServerError;
                    }
                    else
                    {
                        // Any failure in non-buffered mode has already written out StatusCode and possibly content.
                        // This means the client will receive an OK but the content is incomplete.
                        // The proper action here is to abort the connection, but HttpResponse.Abort is a 4.5 feature.
                        // TODO: DevDiv bug #381233 -- call HttpResponse.Abort when it becomes available
                        httpResponseBase.Close();
                    }

                    // We do not propagate any errors up, or we will get the
                    // standard ASP.NET html page.   We want empty content or
                    // a closed connection.
                    return info.Handled();
                })
                .Finally(
                () =>
                {
                    request.DisposeRequestResources();
                    request.Dispose();
                    response.Dispose();
                });
        }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:90,代码来源:HttpControllerHandler.cs

示例11: BufferResponseBodyAsync

 private static async Task<HttpResponseMessage> BufferResponseBodyAsync(HttpRequestMessage request, HttpResponseMessage response)
 {
     try
     {
         await response.Content.LoadIntoBufferAsync();
         return response;
     }
     catch (Exception exception)
     {
         response.Dispose();
         return request.CreateErrorResponse(HttpStatusCode.InternalServerError, exception);
     }
 }
开发者ID:brianly,项目名称:aspnetwebstack,代码行数:13,代码来源:HttpMessageHandlerAdapter.cs

示例12: CreateErrorResponseAsyncCore

 private static async Task CreateErrorResponseAsyncCore(HttpResponseMessage errorResponse, HttpResponseBase httpResponseBase)
 {
     try
     {
         // Asynchronously write the content of the new error HttpResponseMessage
         await errorResponse.Content.CopyToAsync(httpResponseBase.OutputStream);
     }
     catch
     {
         // Failure writing the error response.  Likely cause is a formatter
         // serialization exception.  Create empty error response and
         // return a non-faulted task.
         CreateEmptyErrorResponse(httpResponseBase);
     }
     finally
     {
         // Dispose the temporary HttpResponseMessage carrying the error response
         errorResponse.Dispose();
     }
 }
开发者ID:balajivasudevan,项目名称:aspnetwebstack,代码行数:20,代码来源:HttpControllerHandler.cs

示例13: ConvertResponse

        /// <summary>
        /// Converts a <see cref="HttpResponseMessage"/> to an <see cref="HttpResponseBase"/> and disposes the 
        /// <see cref="HttpResponseMessage"/> and <see cref="HttpRequestMessage"/> upon completion.
        /// </summary>
        /// <param name="httpContextBase">The HTTP context base.</param>
        /// <param name="response">The response to convert.</param>
        /// <param name="request">The request (which will be disposed).</param>
        /// <returns>A <see cref="Task"/> representing the conversion of an <see cref="HttpResponseMessage"/> to an <see cref="HttpResponseBase"/>
        /// including writing out any entity body.</returns>
        internal static async Task ConvertResponse(HttpContextBase httpContextBase, HttpResponseMessage response, HttpRequestMessage request)
        {
            Contract.Assert(httpContextBase != null);
            Contract.Assert(request != null);

            // A null response creates a 500 with no content
            if (response == null)
            {
                CreateEmptyErrorResponse(httpContextBase.Response);
                return;
            }

            CopyResponseStatusAndHeaders(httpContextBase, response);

            // TODO 335085: Consider this when coming up with our caching story
            if (response.Headers.CacheControl == null)
            {
                // DevDiv2 #332323. ASP.NET by default always emits a cache-control: private header.
                // However, we don't want requests to be cached by default.
                // If nobody set an explicit CacheControl then explicitly set to no-cache to override the
                // default behavior. This will cause the following response headers to be emitted:
                //     Cache-Control: no-cache
                //     Pragma: no-cache
                //     Expires: -1
                httpContextBase.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            }

            // Asynchronously write the response body.  If there is no body, we use
            // a completed task to share the Finally() below.
            // The response-writing task will not fault -- it handles errors internally.
            try
            {
                if (response.Content != null)
                {
                    await WriteResponseContentAsync(httpContextBase, response, request);
                }
            }
            finally
            {
                request.DisposeRequestResources();
                request.Dispose();
                response.Dispose();
            }
        }
开发者ID:balajivasudevan,项目名称:aspnetwebstack,代码行数:53,代码来源:HttpControllerHandler.cs

示例14: Execute

        private HttpResponseMessage Execute()
        {
            var httpResponseMessage = new HttpResponseMessage();

            try
            {
                var negotiationResult = ContentNegotiator.Negotiate(typeof(HttpError), Request, Formatters);

                if (negotiationResult == null)
                {
                    httpResponseMessage.StatusCode = HttpStatusCode.NotAcceptable;
                }
                else
                {
                    var error = new HttpError("Internal Server Error");
                    foreach (var property in Exception.GetCustomProperties())
                    {
                        error.Add(property.Key, property.Value);
                    }

                    httpResponseMessage.StatusCode = HttpStatusCode.InternalServerError;
                    httpResponseMessage.Content = new ObjectContent<HttpError>(error, negotiationResult.Formatter, negotiationResult.MediaType);
                }

                httpResponseMessage.RequestMessage = Request;
            }
            catch
            {
                httpResponseMessage.Dispose();
                throw;
            }

            return httpResponseMessage;
        }
开发者ID:magonzalez,项目名称:WebApi-OAuth2-StarterKit,代码行数:34,代码来源:ReferencedExceptionResult.cs

示例15: Execute

        private HttpResponseMessage Execute()
        {
            var httpResponseMessage = new HttpResponseMessage();

            try
            {
                var negotiationResult = ContentNegotiator.Negotiate(typeof(HttpError), Request, Formatters);

                if (negotiationResult == null)
                {
                    httpResponseMessage.StatusCode = HttpStatusCode.NotAcceptable;
                }
                else
                {
                    var error = new HttpError("Validation Failed");
                    foreach (var err in _exception.ValidationErrors)
                    {
                        if (!error.ContainsKey(err.ItemName))
                        {
                            error.Add(err.ItemName, new Collection<ApiError>());
                        }

                        ((ICollection<ApiError>)error[err.ItemName]).Add(new ApiError
                        {
                            ErrorCode = err.ErrorCode,
                            Message = err.ErrorMessage
                        });
                    }

                    httpResponseMessage.StatusCode = HttpStatusCode.BadRequest;
                    httpResponseMessage.Content = new ObjectContent<HttpError>(error, negotiationResult.Formatter, negotiationResult.MediaType);
                }

                httpResponseMessage.RequestMessage = Request;
            }
            catch
            {
                httpResponseMessage.Dispose();
                throw;
            }

            return httpResponseMessage;
        }
开发者ID:magonzalez,项目名称:WebApi-OAuth2-StarterKit,代码行数:43,代码来源:ValidationExceptionResult.cs


注:本文中的System.Net.Http.HttpResponseMessage.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。