當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。