本文整理汇总了C#中System.Net.Http.HttpRequestMessage.GetHttpContext方法的典型用法代码示例。如果您正苦于以下问题:C# HttpRequestMessage.GetHttpContext方法的具体用法?C# HttpRequestMessage.GetHttpContext怎么用?C# HttpRequestMessage.GetHttpContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.HttpRequestMessage
的用法示例。
在下文中一共展示了HttpRequestMessage.GetHttpContext方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetRouteData
public IHttpRouteData GetRouteData(string rootVirtualPath, HttpRequestMessage request)
{
if (rootVirtualPath == null)
{
throw Error.ArgumentNull("rootVirtualPath");
}
if (request == null)
{
throw Error.ArgumentNull("request");
}
HttpContextBase httpContextBase = request.GetHttpContext();
if (httpContextBase == null)
{
httpContextBase = new HttpRequestMessageContextWrapper(rootVirtualPath, request);
}
RouteData routeData = OriginalRoute.GetRouteData(httpContextBase);
if (routeData != null)
{
return new HostedHttpRouteData(routeData);
}
return null;
}
示例2: GetRouteData
/// <inheritdoc/>
public override IHttpRouteData GetRouteData(HttpRequestMessage request)
{
if (request == null)
{
throw Error.ArgumentNull("request");
}
HttpContextBase httpContextBase = request.GetHttpContext();
if (httpContextBase == null)
{
httpContextBase = new HttpRequestMessageContextWrapper(VirtualPathRoot, request);
}
if (httpContextBase.GetHttpRequestMessage() == null)
{
httpContextBase.SetHttpRequestMessage(request);
}
RouteData routeData = _routeCollection.GetRouteData(httpContextBase);
// If the match is from an IgnoreRoute, do not return a RouteData but return a null, which will be treated as a 404 NoRouteMatched.
if (routeData != null && !(routeData.RouteHandler is System.Web.Routing.StopRoutingHandler))
{
return new HostedHttpRouteData(routeData);
}
return null;
}
示例3: GetRouteData
/// <inheritdoc/>
public override IHttpRouteData GetRouteData(HttpRequestMessage request)
{
if (request == null)
{
throw Error.ArgumentNull("request");
}
HttpContextBase httpContextBase = request.GetHttpContext();
if (httpContextBase == null)
{
httpContextBase = new HttpRequestMessageContextWrapper(VirtualPathRoot, request);
}
if (httpContextBase.GetHttpRequestMessage() == null)
{
httpContextBase.SetHttpRequestMessage(request);
}
RouteData routeData = _routeCollection.GetRouteData(httpContextBase);
if (routeData != null)
{
return new HostedHttpRouteData(routeData);
}
return null;
}
示例4: SetupPortalSettings
private static PortalSettings SetupPortalSettings(HttpRequestMessage request)
{
var domainName = TestableGlobals.Instance.GetDomainName(request.RequestUri);
var alias = PortalAliasController.Instance.GetPortalAlias(domainName);
int tabId;
ValidateTabAndModuleContext(request, alias.PortalID, out tabId);
var portalSettings = new PortalSettings(tabId, alias);
request.GetHttpContext().Items["PortalSettings"] = portalSettings;
return portalSettings;
}
示例5: SendAsync
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var httpContext = request.GetHttpContext();
string clientIp = httpContext.Request.UserHostAddress;
string msg = string.Format("IP:[{0}] ,Method:[{1}], Url:[{2}]",
clientIp,
httpContext.Request.HttpMethod,
httpContext.Request.RawUrl
);
logger.Info(msg);
return base.SendAsync(request, cancellationToken);
}
示例6: GetHttpContext
private static HttpContextBase GetHttpContext(HttpRequestMessage request)
{
if (request == null)
{
throw new ArgumentNullException("request");
}
HttpContextBase context = request.GetHttpContext();
if (context == null)
{
throw new InvalidOperationException(SRResources.HttpContextPropertyMissing);
}
return context;
}
示例7: GetVirtualPath
public IHttpVirtualPathData GetVirtualPath(HttpRequestMessage request, IDictionary<string, object> values)
{
if (request == null)
{
throw Error.ArgumentNull("request");
}
HttpContextBase httpContextBase = request.GetHttpContext();
if (httpContextBase != null)
{
HostedHttpRouteData routeData = request.GetRouteData() as HostedHttpRouteData;
if (routeData != null)
{
RequestContext requestContext = new RequestContext(httpContextBase, routeData.OriginalRouteData);
VirtualPathData virtualPathData = OriginalRoute.GetVirtualPath(requestContext, new RouteValueDictionary(values));
if (virtualPathData != null)
{
return new HostedHttpVirtualPathData(virtualPathData, routeData.Route);
}
}
}
return null;
}
示例8: ShouldBypassPartialResponse
/// <summary>
/// Returns a value that indicates whether partial response should be bypassed.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>True if the partial response should be bypassed, otherwise false.</returns>
protected virtual bool ShouldBypassPartialResponse(HttpRequestMessage request)
{
if (request == null)
{
throw new ArgumentNullException("request");
}
if (request.GetBypassPartialResponse())
{
return true;
}
var httpContext = request.GetHttpContext();
if (httpContext != null)
{
return httpContext.Response.StatusCode != 200;
}
return false;
}
示例9: RetrieveClientCertificate
private static X509Certificate2 RetrieveClientCertificate(HttpRequestMessage request)
{
if (request == null)
{
throw Error.ArgumentNull("request");
}
X509Certificate2 result = null;
HttpContextBase httpContextBase = request.GetHttpContext();
if (httpContextBase != null)
{
if (httpContextBase.Request.ClientCertificate.Certificate != null && httpContextBase.Request.ClientCertificate.Certificate.Length > 0)
{
result = new X509Certificate2(httpContextBase.Request.ClientCertificate.Certificate);
}
}
return result;
}
示例10: GetVirtualPath
/// <inheritdoc/>
public override IHttpVirtualPathData GetVirtualPath(HttpRequestMessage request, string name, IDictionary<string, object> values)
{
if (request == null)
{
throw Error.ArgumentNull("request");
}
HttpContextBase httpContextBase = request.GetHttpContext();
if (httpContextBase == null)
{
httpContextBase = new HttpRequestMessageContextWrapper(VirtualPathRoot, request);
}
if (httpContextBase.GetHttpRequestMessage() == null)
{
httpContextBase.SetHttpRequestMessage(request);
}
IHttpRouteData routeData = request.GetRouteData();
if (routeData == null)
{
return null;
}
RequestContext requestContext = new RequestContext(httpContextBase, routeData.ToRouteData());
RouteValueDictionary routeValues = values != null ? new RouteValueDictionary(values) : new RouteValueDictionary();
VirtualPathData virtualPathData = _routeCollection.GetVirtualPath(requestContext, name, routeValues);
if (virtualPathData != null)
{
// If the route is not an HttpWebRoute, try getting a virtual path without the httproute key in the route value dictionary
// This ensures that httproute isn't picked up by non-WebAPI routes that might pollute the virtual path with httproute
if (!(virtualPathData.Route is HttpWebRoute))
{
if (routeValues.Remove(HttpWebRoute.HttpRouteKey))
{
VirtualPathData virtualPathDataWithoutHttpRouteValue = _routeCollection.GetVirtualPath(requestContext, name, routeValues);
if (virtualPathDataWithoutHttpRouteValue != null)
{
virtualPathData = virtualPathDataWithoutHttpRouteValue;
}
}
}
return new HostedHttpVirtualPathData(virtualPathData, routeData.Route);
}
return null;
}
示例11: SetCurrentPrincipal
protected static void SetCurrentPrincipal(IPrincipal principal, HttpRequestMessage request)
{
Thread.CurrentPrincipal = principal;
request.GetHttpContext().User = principal;
}
示例12: ProcessRequest
protected override HttpRequestMessage ProcessRequest(HttpRequestMessage request, CancellationToken cancellationToken)
{
MembershipModule.AuthenticateRequest(request.GetHttpContext(), allowUnknownExtensinons: true);
return request;
}