本文整理匯總了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;
}