本文整理汇总了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;
}
}
示例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));
}
}
示例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);
}
示例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();
}
}
示例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();
}
}
}
示例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);
}
示例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);
}
}
示例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();
}
}
}