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


C# HttpRequestMessage.GetHttpContext方法代码示例

本文整理汇总了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;
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:26,代码来源:HostedHttpRoute.cs

示例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;
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:28,代码来源:HostedHttpRouteCollection.cs

示例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;
        }
开发者ID:brianly,项目名称:aspnetwebstack,代码行数:27,代码来源:HostedHttpRouteCollection.cs

示例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;
        }
开发者ID:VegasoftTI,项目名称:Dnn.Platform,代码行数:13,代码来源:DnnContextMessageHandler.cs

示例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);
        }
开发者ID:john123951,项目名称:sweetfly.net,代码行数:15,代码来源:TraceHandler.cs

示例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;
        }
开发者ID:brianly,项目名称:aspnetwebstack,代码行数:16,代码来源:WebHostPrincipalService.cs

示例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;
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:24,代码来源:HostedHttpRoute.cs

示例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;
        }
开发者ID:ath2o,项目名称:PartialResponse,代码行数:26,代码来源:PartialJsonMediaTypeFormatter.cs

示例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;
        }
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:20,代码来源:HttpControllerHandler.cs

示例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;
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:50,代码来源:HostedHttpRouteCollection.cs

示例11: SetCurrentPrincipal

 protected static void SetCurrentPrincipal(IPrincipal principal, HttpRequestMessage request)
 {
     Thread.CurrentPrincipal = principal;
     request.GetHttpContext().User = principal;
 }
开发者ID:rut5949,项目名称:Dnn.Platform,代码行数:5,代码来源:AuthMessageHandlerBase.cs

示例12: ProcessRequest

        protected override HttpRequestMessage ProcessRequest(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            MembershipModule.AuthenticateRequest(request.GetHttpContext(), allowUnknownExtensinons: true);

            return request;
        }
开发者ID:davidsports,项目名称:Dnn.Platform,代码行数:6,代码来源:WebFormsAuthMessageHandler.cs


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