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


C# HttpContextBase.GetOrCreateHttpRequestMessage方法代码示例

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


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

示例1: GetRouteData

 public override RouteData GetRouteData(HttpContextBase httpContext)
 {
     try
     {
         if (HttpRoute is HostedHttpRoute)
         {
             return base.GetRouteData(httpContext);
         }
         else
         {
             // if user passed us a custom IHttpRoute, then we should invoke their function instead of the base
             HttpRequestMessage request = httpContext.GetOrCreateHttpRequestMessage();
             IHttpRouteData data = HttpRoute.GetRouteData(httpContext.Request.ApplicationPath, request);
             return data == null ? null : data.ToRouteData();
         }
     }
     catch (HttpResponseException e)
     {
         // Task.Wait is fine here as ConvertResponse calls into MediaTypeFormatter.WriteToStreamAsync which happens
         // synchronously in the default case (our default formatters are synchronous).
         HttpControllerHandler.ConvertResponse(httpContext, e.Response, httpContext.GetOrCreateHttpRequestMessage()).Wait();
         httpContext.Response.End();
         return null;
     }
 }
开发者ID:normalian,项目名称:aspnetwebstack,代码行数:25,代码来源:HttpWebRoute.cs

示例2: GetRouteData

 public override RouteData GetRouteData(HttpContextBase httpContext)
 {
     try
     {
         if (HttpRoute is HostedHttpRoute)
         {
             return base.GetRouteData(httpContext);
         }
         else
         {
             // if user passed us a custom IHttpRoute, then we should invoke their function instead of the base
             HttpRequestMessage request = httpContext.GetOrCreateHttpRequestMessage();
             IHttpRouteData data = HttpRoute.GetRouteData(httpContext.Request.ApplicationPath, request);
             return data == null ? null : data.ToRouteData();
         }
     }
     catch (Exception exception)
     {
         // Processing an exception involves async work, and this method is synchronous.
         // Instead of waiting on the async work here, it's better to return a handler that will deal with the
         // exception asynchronously during its request processing method.
         ExceptionDispatchInfo exceptionInfo = ExceptionDispatchInfo.Capture(exception);
         return new RouteData(this, new HttpRouteExceptionRouteHandler(exceptionInfo));
     }
 }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:25,代码来源:HttpWebRoute.cs

示例3: 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.GetOrCreateHttpRequestMessage();
                return httpRouteConstraint.Match(request, HttpRoute, parameterName, values, ConvertRouteDirection(routeDirection));
            }

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

示例4: GetRouteData

 public override RouteData GetRouteData(HttpContextBase httpContext)
 {
     if (HttpRoute is HostedHttpRoute)
     {
         return base.GetRouteData(httpContext);
     }
     else
     {
         // if user passed us a custom IHttpRoute, then we should invoke their function instead of the base
         HttpRequestMessage request = httpContext.GetOrCreateHttpRequestMessage();
         IHttpRouteData data = HttpRoute.GetRouteData(httpContext.Request.ApplicationPath, request);
         return data == null ? null : data.ToRouteData();
     }
 }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:14,代码来源:HttpWebRoute.cs

示例5: ProcessRequestAsync

        internal async Task ProcessRequestAsync(HttpContextBase context)
        {
            Exception exception = _exceptionInfo.SourceException;
            Contract.Assert(exception != null);

            HttpRequestMessage request = context.GetOrCreateHttpRequestMessage();
            HttpResponseMessage response = null;
            CancellationToken cancellationToken = context.Response.GetClientDisconnectedTokenWhenFixed();

            HttpResponseException responseException = exception as HttpResponseException;

            try
            {
                if (responseException != null)
                {
                    response = responseException.Response;
                    Contract.Assert(response != null);

                    // This method call is hardened and designed not to throw exceptions (since they won't be caught
                    // and handled further by its callers).
                    await HttpControllerHandler.CopyResponseAsync(context, request, response, _exceptionLogger,
                        _exceptionHandler, cancellationToken);
                }
                else
                {
                    // This method call is hardened and designed not to throw exceptions (since they won't be caught and
                    // handled further by its callers).
                    bool handled = await HttpControllerHandler.CopyErrorResponseAsync(
                        WebHostExceptionCatchBlocks.HttpWebRoute, context, request, null,
                        _exceptionInfo.SourceException, _exceptionLogger, _exceptionHandler, cancellationToken);

                    if (!handled)
                    {
                        _exceptionInfo.Throw();
                    }
                }
            }
            finally
            {
                // The other HttpTaskAsyncHandler is HttpControllerHandler; it has similar cleanup logic.
                request.DisposeRequestResources();
                request.Dispose();

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

示例6: ProcessConstraint

        protected override bool ProcessConstraint(HttpContextBase httpContext, object constraint, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
        {
            // The base class will validate that a constraint is either a string or IRoutingConstraint inside its
            // ProcessConstraint method. We're doing the validation up front here because we also support 
            // IHttpRouteConstraint and we want the error message to reflect all three valid possibilities.
            ValidateConstraint(HttpRoute.RouteTemplate, parameterName, constraint);

            IHttpRouteConstraint httpRouteConstraint = constraint as IHttpRouteConstraint;
            if (httpRouteConstraint != null)
            {
                HttpRequestMessage request = httpContext.GetOrCreateHttpRequestMessage();
                return httpRouteConstraint.Match(request, HttpRoute, parameterName, values, ConvertRouteDirection(routeDirection));
            }

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

示例7: GetRouteData

 public override RouteData GetRouteData(HttpContextBase httpContext)
 {
     try
     {
         if (HttpRoute is HostedHttpRoute)
         {
             return base.GetRouteData(httpContext);
         }
         else
         {
             // if user passed us a custom IHttpRoute, then we should invoke their function instead of the base
             HttpRequestMessage request = httpContext.GetOrCreateHttpRequestMessage();
             IHttpRouteData data = HttpRoute.GetRouteData(httpContext.Request.ApplicationPath, request);
             return data == null ? null : data.ToRouteData();
         }
     }
     catch (HttpResponseException e)
     {
         // Treat HttpResponseExceptions as matching routes but bad requests. As IHttpRoute cannot short circuit the response pipeline,
         // stash the routing error response on the request so that HttpRoutingDispatcher can retrieve it back and return that error response.
         httpContext.SetRoutingError(e.Response);
         return new RouteData(this, HttpControllerRouteHandler.Instance);
     }
 }
开发者ID:samgithub-duplicate,项目名称:aspnetwebstack,代码行数:24,代码来源:HttpWebRoute.cs

示例8: ProcessRequestAsync

        internal async Task ProcessRequestAsync(HttpContextBase context)
        {
            Exception exception = _exceptionInfo.SourceException;
            Contract.Assert(exception != null);

            OperationCanceledException canceledException = exception as OperationCanceledException;
            if (canceledException != null)
            {
                // If the route throws a cancelation exception, then we'll abort the request instead of
                // reporting an 'error'. We don't expect this to happen, but aborting the request is 
                // consistent with our behavior in other hosts.
                context.Request.Abort();
                return;
            }

            HttpRequestMessage request = context.GetOrCreateHttpRequestMessage();
            HttpResponseMessage response = null;
            CancellationToken cancellationToken = context.Response.GetClientDisconnectedTokenWhenFixed();

            HttpResponseException responseException = exception as HttpResponseException;

            try
            {
                if (responseException != null)
                {
                    response = responseException.Response;
                    Contract.Assert(response != null);

                    // This method call is hardened and designed not to throw exceptions (since they won't be caught
                    // and handled further by its callers).
                    await HttpControllerHandler.CopyResponseAsync(context, request, response, _exceptionLogger,
                        _exceptionHandler, cancellationToken);
                }
                else
                {
                    // This method call is hardened and designed not to throw exceptions (since they won't be caught and
                    // handled further by its callers).
                    bool handled = await HttpControllerHandler.CopyErrorResponseAsync(
                        WebHostExceptionCatchBlocks.HttpWebRoute, context, request, null,
                        _exceptionInfo.SourceException, _exceptionLogger, _exceptionHandler, cancellationToken);

                    if (!handled)
                    {
                        _exceptionInfo.Throw();
                    }
                }
            }
            catch (OperationCanceledException)
            {
                // This block handles cancellations that might occur while we're writing an 'error' response.
                //
                // 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.
                context.Request.Abort();
            }
            finally
            {
                // The other HttpTaskAsyncHandler is HttpControllerHandler; it has similar cleanup logic.
                request.DisposeRequestResources();
                request.Dispose();

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


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