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


C# HttpContextBase.GetHttpRequestMessage方法代码示例

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


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

示例1: ProcessConstraint

        protected override bool ProcessConstraint(HttpContextBase httpContext, object constraint, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
        {
            IHttpRouteConstraint httpRouteConstraint = constraint as IHttpRouteConstraint;
            if (httpRouteConstraint != null)
            {
                HttpRequestMessage request = httpContext.GetHttpRequestMessage();
                if (request == null)
                {
                    request = HttpControllerHandler.ConvertRequest(httpContext);
                    httpContext.SetHttpRequestMessage(request);
                }

                return httpRouteConstraint.Match(request, HttpRoute, parameterName, values, ConvertRouteDirection(routeDirection));
            }

            return base.ProcessConstraint(httpContext, constraint, parameterName, values, routeDirection);
        }
开发者ID:reza899,项目名称:aspnetwebstack,代码行数:17,代码来源:HttpWebRoute.cs

示例2: ProcessRequestAsyncCore

        internal async Task ProcessRequestAsyncCore(HttpContextBase contextBase)
        {
            HttpRequestMessage request = contextBase.GetHttpRequestMessage() ?? ConvertRequest(contextBase);

            // Add route data
            request.SetRouteData(_routeData);
            CancellationToken cancellationToken = contextBase.Response.GetClientDisconnectedTokenWhenFixed();
            HttpResponseMessage response = null;

            try
            {
                response = await _server.SendAsync(request, cancellationToken);
                await CopyResponseAsync(contextBase, request, response, _exceptionLogger.Value, _exceptionHandler.Value,
                    cancellationToken);
            }
            finally
            {
                // The other HttpTaskAsyncHandler is HttpRouteExceptionHandler; it has similar cleanup logic.
                request.DisposeRequestResources();
                request.Dispose();

                if (response != null)
                {
                    response.Dispose();
                }
            }
        }
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:27,代码来源:HttpControllerHandler.cs

示例3: ProcessRequestAsyncCore

        internal async Task ProcessRequestAsyncCore(HttpContextBase contextBase)
        {
            HttpRequestMessage request = contextBase.GetHttpRequestMessage() ?? ConvertRequest(contextBase);

            // Add route data
            request.Properties[HttpPropertyKeys.HttpRouteDataKey] = _routeData;

            HttpResponseMessage response = await _server.SendAsync(request, contextBase.Request.TimedOutToken);
            await ConvertResponse(contextBase, response, request);
        }
开发者ID:balajivasudevan,项目名称:aspnetwebstack,代码行数:10,代码来源:HttpControllerHandler.cs

示例4: ProcessRequestAsyncCore

        internal async Task ProcessRequestAsyncCore(HttpContextBase contextBase)
        {
            HttpRequestMessage request = contextBase.GetHttpRequestMessage() ?? ConvertRequest(contextBase);

            // Add route data
            request.SetRouteData(_routeData);
            CancellationToken cancellationToken = contextBase.Response.GetClientDisconnectedTokenWhenFixed();
            HttpResponseMessage response = null;

            try
            {
                response = await _server.SendAsync(request, cancellationToken);
                await CopyResponseAsync(contextBase, request, response, _exceptionLogger.Value, _exceptionHandler.Value,
                    cancellationToken);
            }
            catch (OperationCanceledException)
            {
                // HttpTaskAsyncHandler treats a canceled task as an unhandled exception (logged to Application event
                // log). Instead of returning a canceled task, abort the request and return a completed task.
                contextBase.Request.Abort();
            }
            finally
            {
                // The other HttpTaskAsyncHandler is HttpRouteExceptionHandler; it has similar cleanup logic.
                request.DisposeRequestResources();
                request.Dispose();

                if (response != null)
                {
                    response.Dispose();
                }
            }
        }
开发者ID:wjkhappy14,项目名称:aspnetwebstack,代码行数:33,代码来源:HttpControllerHandler.cs

示例5: BeginProcessRequest

        protected virtual IAsyncResult BeginProcessRequest(HttpContextBase httpContextBase, AsyncCallback callback, object state)
        {
            HttpRequestMessage request = httpContextBase.GetHttpRequestMessage() ?? ConvertRequest(httpContextBase);

            // Add route data
            request.Properties[HttpPropertyKeys.HttpRouteDataKey] = _routeData;

            Task responseBodyTask = _server.Value.SendAsync(request, CancellationToken.None)
                .Then(response => ConvertResponse(httpContextBase, response, request));

            TaskWrapperAsyncResult result = new TaskWrapperAsyncResult(responseBodyTask, state);

            if (callback != null)
            {
                if (result.IsCompleted)
                {
                    // If the underlying task is already finished, from our caller's perspective this is just
                    // a synchronous completion. See also DevDiv #346170.
                    result.CompletedSynchronously = true;
                    callback(result);
                }
                else
                {
                    // If the underlying task isn't yet finished, from our caller's perspective this will be
                    // an asynchronous completion. We'll use ContinueWith instead of Finally for two reasons:
                    //
                    // - Finally propagates the antecedent Task's exception, which we don't need to do here.
                    //   Out caller will eventually call EndProcessRequest, which correctly observes the
                    //   antecedent Task's exception anyway if it faulted.
                    //
                    // - Finally invokes the callback on the captured SynchronizationContext, which is
                    //   unnecessary when using APM (Begin / End). APM assumes that the callback is invoked
                    //   on an arbitrary ThreadPool thread with no SynchronizationContext set up, so
                    //   ContinueWith gets us closer to the desired semantic.
                    //
                    // There is still a race here: the Task might complete after the IsCompleted check above,
                    // so the callback might be invoked on another thread concurrently with the original
                    // thread's call to BeginProcessRequest. But we shouldn't concern ourselves with that;
                    // the caller has to be prepared for that possibility and do the right thing. We also
                    // don't need to worry about the callback throwing since the caller should give us a
                    // callback which is well-behaved.
                    result.CompletedSynchronously = false;
                    responseBodyTask.ContinueWith(_ =>
                    {
                        callback(result);
                    });
                }
            }

            return result;
        }
开发者ID:marojeri,项目名称:aspnetwebstack,代码行数:51,代码来源:HttpControllerHandler.cs

示例6: ProcessRequestAsyncCore

        internal async Task ProcessRequestAsyncCore(HttpContextBase contextBase)
        {
            HttpRequestMessage request = contextBase.GetHttpRequestMessage() ?? ConvertRequest(contextBase);

            // Add route data
            request.SetRouteData(_routeData);

            HttpResponseMessage response = await _server.SendAsync(request, CancellationToken.None);
            await ConvertResponse(contextBase, response, request);
        }
开发者ID:khorchani,项目名称:aspnetwebstack,代码行数:10,代码来源:HttpControllerHandler.cs


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