Exemplo n.º 1
0
        private void PostResolveRequestCache(HttpContextBase context)
        {
            RouteData routeData = RouteTable.Routes.GetRouteData(context);

            if (routeData == null)
            {
                throw new InvalidOperationException();
            }

            IRouteHandler routeHandler = routeData.RouteHandler;

            if (routeHandler == null)
            {
                throw new InvalidOperationException();
            }

            RequestContext requestContext = new RequestContext(context, routeData);
            IHttpHandler   httpHandler    = routeHandler.GetHttpHandler(requestContext);

            if (httpHandler == null)
            {
                throw new InvalidOperationException("无法创建对应的HttpHandler对象");
            }
            context.RemapHandler(httpHandler);
        }
Exemplo n.º 2
0
        protected override void ProcessRequest(HttpContextBase httpContext)
        {
            RouteCollection coll = SiteManager.Current.GetRouteCollection();

            if (coll == null || coll.Count == 0)
            {
                SiteManager.Current.ReloadConfigration();
                return;
            }
            RouteData routeData = coll.GetRouteData(httpContext);

            if (routeData == null)
            {
                httpContext.Response.Redirect("/PageNotFound", false);
                return;
            }

            IRouteHandler routeHandler = routeData.RouteHandler;

            if (routeHandler == null)
            {
                throw new InvalidOperationException("MvcHttpHandlerEx.ProcessRequest, No Route Handler");
            }
            RequestContext requestContext = new RequestContext(httpContext, routeData);
            IHttpHandler   httpHandler    = routeHandler.GetHttpHandler(requestContext);

            if (httpHandler == null)
            {
                throw new InvalidOperationException("MvcHttpHandlerEx.ProcessRequest, httpHandler is null!");
            }


            this.VerifyAndProcessRequest(httpHandler, httpContext);
        }
Exemplo n.º 3
0
        public virtual void PostResolveRequestCache(HttpContextBase context)
        {
            RouteData routeData = RouteCollection.GetRouteData(context);

            if (routeData == null)
            {
                return;
            }
            IRouteHandler routeHandler = routeData.RouteHandler;

            if (routeHandler == null)
            {
                return;
            }

            RequestContext requestContext = new RequestContext(context, routeData);

            context.Request.RequestContext = requestContext;


            IHttpHandler httpHandler = routeHandler.GetHttpHandler(requestContext);

            if (httpHandler == null)
            {
                return;
            }
            context.RemapHandler(httpHandler);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Finds the appropriate route for the specified
        /// HTTP request and rewrites the execution path,
        /// if necessary
        /// </summary>
        /// <param name="context">The current HTTP request context</param>
        public virtual void PostResolveRequestCache(HttpContextBase context)
        {
            RouteData data = Routes.GetRouteData(context);

            if (data == null)
            {
                return;
            }

            IRouteHandler handler = data.Handler;

            if (handler == null)
            {
                throw Error.NoRouteHandlerFound();
            }

            if (handler is StopRoutingHandler) // если надо тормознуть, тормозим
            {
                return;
            }

            RequestContext requestContext = new RequestContext(context, data);
            IHttpHandler   httpHandler    = handler.GetHttpHandler(requestContext);

            if (httpHandler == null)
            {
                throw Error.NoHttpHandlerFound(handler.GetType());
            }

            context.Items[_requestDataKey] =
                new RequestData(httpHandler, context.Request.Path);

            context.RewritePath("~/wahha.routing.axd");
        }
Exemplo n.º 5
0
        protected virtual void ProcessRequest(HttpContextBase httpContext)
        {
            RouteData routeData = RouteCollection.GetRouteData(httpContext);

            if (routeData == null)
            {
                throw new HttpException(404, SR.GetString(SR.UrlRoutingHandler_NoRouteMatches));
            }

            IRouteHandler routeHandler = routeData.RouteHandler;

            if (routeHandler == null)
            {
                throw new InvalidOperationException(SR.GetString(SR.UrlRoutingModule_NoRouteHandler));
            }

            RequestContext requestContext = new RequestContext(httpContext, routeData);
            IHttpHandler   httpHandler    = routeHandler.GetHttpHandler(requestContext);

            if (httpHandler == null)
            {
                throw new InvalidOperationException(
                          String.Format(
                              CultureInfo.CurrentUICulture,
                              SR.GetString(SR.UrlRoutingModule_NoHttpHandler),
                              routeHandler.GetType()));
            }

            VerifyAndProcessRequest(httpHandler, httpContext);
        }
Exemplo n.º 6
0
        private void Context_BeginRequest(object sender, EventArgs e)
        {
            HttpApplication app = (HttpApplication)sender;

            if (app != null)
            {
                HttpContext currentHttpContent = app.Context;
                RouteData   routeData          = RouteTable.Routes.GetRouteData(currentHttpContent);
                if (routeData == null)
                {
                    return;
                    //throw new HttpException(404, "没有找到匹配的路由规则!");
                }

                IRouteHandler routeHandler = routeData.RouteHandler;
                if (routeHandler == null)
                {
                    return;
                }

                IHttpHandler currentHandler = routeHandler.GetHttpHandler(routeData, currentHttpContent);
                //设置当前处理程序
                currentHttpContent.RemapHandler(currentHandler);
            }
        }
Exemplo n.º 7
0
        public virtual void PostResolveRequestCache(HttpContextBase context)
        {
            //1.传入当前上下文对象,得到与当前请求匹配的SwiftRouteData对象
            SwiftRouteData routeData = this.SwiftRouteCollection.GetRouteData(context);

            if (routeData == null)
            {
                return;
            }
            //2.从SwiftRouteData对象里面得到当前的RouteHandler对象。
            IRouteHandler routeHandler = routeData.RouteHandler;

            if (routeHandler == null)
            {
                return;
            }

            //3.根据RequestContext对象得到处理当前请求的HttpHandler(MvcHandler)。
            IHttpHandler httpHandler = routeHandler.GetHttpHandler(routeData, context);

            if (httpHandler == null)
            {
                return;
            }

            //4.请求转到HttpHandler进行处理(进入到ProcessRequest方法)。这一步很重要,由这一步开始,请求才由UrlRoutingModule转到了MvcHandler里面
            context.RemapHandler(httpHandler);
        }
Exemplo n.º 8
0
        public virtual void PostResolveRequestCache(HttpContextBase context)
        {
            RouteData routeData = this.RouteCollection.GetRouteData(context);

            if (routeData != null)
            {
                IRouteHandler routeHandler = routeData.RouteHandler;
                if (routeHandler == null)
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, System.Web.SR.GetString("UrlRoutingModule_NoRouteHandler"), new object[0]));
                }
                if (!(routeHandler is StopRoutingHandler))
                {
                    RequestContext requestContext = new RequestContext(context, routeData);
                    context.Request.RequestContext = requestContext;
                    IHttpHandler httpHandler = routeHandler.GetHttpHandler(requestContext);
                    if (httpHandler == null)
                    {
                        throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, System.Web.SR.GetString("UrlRoutingModule_NoHttpHandler"), new object[] { routeHandler.GetType() }));
                    }
                    if (httpHandler is UrlAuthFailureHandler)
                    {
                        if (!FormsAuthenticationModule.FormsAuthRequired)
                        {
                            throw new HttpException(0x191, System.Web.SR.GetString("Assess_Denied_Description3"));
                        }
                        UrlAuthorizationModule.ReportUrlAuthorizationFailure(HttpContext.Current, this);
                    }
                    else
                    {
                        context.RemapHandler(httpHandler);
                    }
                }
            }
        }
Exemplo n.º 9
0
        public void StopRoutingHandlerDefault()
        {
            StopRoutingHandler srh = new StopRoutingHandler();

            IRouteHandler rh = srh as IRouteHandler;

            Assert.NotNull(rh);
            Assert.Throws <NotSupportedException>(() => rh.GetHttpHandler(null));
        }
Exemplo n.º 10
0
    public IHttpHandler GetHttpHandler(RequestContext requestContext)
    {
        var values = requestContext.RouteData.Values;

        if (values.ContainsKey("controller"))
        {
            values["controller"] = "Admin" + values["controller"];
        }
        return(_mvcHandler.GetHttpHandler(requestContext));
    }
Exemplo n.º 11
0
            public IHttpHandler GetHttpHandler(RequestContext requestContext)
            {
                var httpHandler = _routeHandler.GetHttpHandler(requestContext);

                if (httpHandler is IHttpAsyncHandler)
                {
                    return(new HttpAsyncHandler(_workContextAccessor, (IHttpAsyncHandler)httpHandler));
                }
                return(new HttpHandler(_workContextAccessor, httpHandler));
            }
Exemplo n.º 12
0
            public IHttpHandler GetHttpHandler(RequestContext requestContext)
            {
                var httpHandler      = routeHandler.GetHttpHandler(requestContext);
                var httpAsyncHandler = httpHandler as IHttpAsyncHandler;

                if (httpAsyncHandler != null)
                {
                    return(new HttpAsyncHandler(workContextAccessor, httpAsyncHandler));
                }
                return(new HttpHandler(workContextAccessor, httpHandler));
            }
Exemplo n.º 13
0
        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            if (RoutingConfigurationProvider.GetRoutingConfiguration().LegacyRoutes301RedirectEnabled)
            {
                return(requestContext.HttpContext.Request.HttpMethod.Equals("GET", System.StringComparison.InvariantCultureIgnoreCase)
                                        ? new RedirectToRoutePermanentHttpHandler(requestContext.RouteData.Values) as IHttpHandler
                                        : new RedirectToRoutePreserveMethodHttpHandler(requestContext.RouteData.Values) as IHttpHandler);
            }

            return(Handler.GetHttpHandler(requestContext));
        }
Exemplo n.º 14
0
            public IHttpHandler GetHttpHandler(RequestContext requestContext)
            {
                var httpHandler = _routeHandler.GetHttpHandler(requestContext);

                requestContext.HttpContext.SetSessionStateBehavior(_sessionStateBehavior);

                if (httpHandler is IHttpAsyncHandler)
                {
                    return(new HttpAsyncHandler(_workContextAccessor, (IHttpAsyncHandler)httpHandler));
                }
                return(new HttpHandler(_workContextAccessor, httpHandler));
            }
Exemplo n.º 15
0
 public void ProcessRootRequest(RootRoute route, IRouteHandler routeHandler)
 {
     // todo: unit test this method
     var request = HttpContext.Request;
     RouteData routeData = route.GetRouteData(HttpContext);
     var requestContext = new RequestContext(HttpContext, routeData);
     string originalPath = request.Path;
     HttpContext.RewritePath(request.ApplicationPath, false);
     IHttpHandler httpHandler = routeHandler.GetHttpHandler(requestContext);
     httpHandler.ProcessRequest(System.Web.HttpContext.Current);
     HttpContext.RewritePath(originalPath);
 }
Exemplo n.º 16
0
        public void ProcessRootRequest(RootRoute route, IRouteHandler routeHandler)
        {
            // todo: unit test this method
            var       request        = HttpContext.Request;
            RouteData routeData      = route.GetRouteData(HttpContext);
            var       requestContext = new RequestContext(HttpContext, routeData);
            string    originalPath   = request.Path;

            HttpContext.RewritePath(request.ApplicationPath, false);
            IHttpHandler httpHandler = routeHandler.GetHttpHandler(requestContext);

            httpHandler.ProcessRequest(System.Web.HttpContext.Current);
            HttpContext.RewritePath(originalPath);
        }
Exemplo n.º 17
0
        public void GetHttpHandler_ReturnsExceptionHandlerWithExceptionInfo()
        {
            // Arrange
            ExceptionDispatchInfo expectedExceptionInfo = CreateExceptionInfo();
            IRouteHandler         product        = CreateProductUnderTest(expectedExceptionInfo);
            RequestContext        requestContext = null;

            // Act
            IHttpHandler handler = product.GetHttpHandler(requestContext);

            // Assert
            HttpRouteExceptionHandler typedHandler = Assert.IsType <HttpRouteExceptionHandler>(handler);

            Assert.Same(expectedExceptionInfo, typedHandler.ExceptionInfo);
        }
Exemplo n.º 18
0
        protected virtual void ProcessRequest(HttpContextBase context)
        {
            RouteData data = Routes.GetRouteData(context);

            Precondition.Require(data, () => Error.NoRouteMatched());

            IRouteHandler handler = data.Handler;

            Precondition.Require(handler, () => Error.NoRouteHandlerFound());

            RequestContext ctx         = new RequestContext(context, data);
            IHttpHandler   httpHandler = handler.GetHttpHandler(ctx);

            Precondition.Require(httpHandler, () => Error.NoHttpHandlerFound(handler.GetType()));

            VerifyAndProcessRequest(httpHandler, context);
        }
Exemplo n.º 19
0
        protected virtual void ProcessRequest(HttpContextBase httpContext)
        {
            RouteData routeData = this.RouteCollection.GetRouteData(httpContext);

            if (routeData == null)
            {
                throw new HttpException(0x194, System.Web.SR.GetString("UrlRoutingHandler_NoRouteMatches"));
            }
            IRouteHandler routeHandler = routeData.RouteHandler;

            if (routeHandler == null)
            {
                throw new InvalidOperationException(System.Web.SR.GetString("UrlRoutingModule_NoRouteHandler"));
            }
            RequestContext requestContext = new RequestContext(httpContext, routeData);
            IHttpHandler   httpHandler    = routeHandler.GetHttpHandler(requestContext);

            if (httpHandler == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, System.Web.SR.GetString("UrlRoutingModule_NoHttpHandler"), new object[] { routeHandler.GetType() }));
            }
            this.VerifyAndProcessRequest(httpHandler, httpContext);
        }
Exemplo n.º 20
0
        public void MrCMSRouteHandler_GetHttpHandler_ReturnsMrCMSHttpHandler()
        {
            IRouteHandler mrCMSRouteHandler = GetMrCMSRouteHandler();

            mrCMSRouteHandler.GetHttpHandler(A.Fake <RequestContext>()).Should().BeOfType <MrCMSHttpHandler>();
        }
Exemplo n.º 21
0
        // [Obsolete("This method is obsolete. Override the Init method to use the PostMapRequestHandler event.")]
        // public virtual void PostMapRequestHandler(HttpContextBase context)

        #endregion

        public virtual void PostResolveRequestCache(HttpContextBase context)
        {
            // Match the incoming URL against the route table
            RouteData routeData = RouteCollection.GetRouteData(context);

            // Do nothing if no route found
            if (routeData == null)
            {
                SegmentLang.Instance.ResolveRequest(context, routeData);
                return;
            }

            // If a route was found, get an IHttpHandler from the route's RouteHandler
            IRouteHandler routeHandler = routeData.RouteHandler;

            if (routeHandler == null)
            {
                SegmentLang.Instance.ResolveRequest(context, routeData);

                throw new InvalidOperationException(
                          String.Format(
                              CultureInfo.CurrentCulture, "NoRouteHandler"));
            }

            // This is a special IRouteHandler that tells the routing module to stop processing
            // routes and to let the fallback handler handle the request.
            if (routeHandler is StopRoutingHandler)
            {
                return;
            }

            RequestContext requestContext = new RequestContext(context, routeData);

            // Dev10 766875	Adding RouteData to HttpContext
            context.Request.RequestContext = requestContext;

            // AiLib
            SegmentLang.Instance.ResolveRequest(context, routeData);

            IHttpHandler httpHandler = routeHandler.GetHttpHandler(requestContext);

            if (httpHandler == null)
            {
                throw new InvalidOperationException(
                          String.Format(
                              CultureInfo.CurrentUICulture,
                              "NoHttpHandler {0}",
                              routeHandler.GetType())
                          );
            }

            var fullName = httpHandler.GetType().FullName;

            // (httpHandler is UrlAuthFailureHandler)
            if (fullName.Contains("UrlAuthFailure")) // System.Web.Routing.UrlAuthFailureHandler
            {
                //if (FormsAuthenticationModule.FormsAuthRequired)
                //{
                //    UrlAuthorizationModule.ReportUrlAuthorizationFailure(HttpContext.Current, this);
                //    return;
                throw new HttpException(401, "Access denied"); // _Description3
            }

            // Remap IIS7 to our handler:
            // class System.Web.HttpContextBase
            // virtual void RemapHandler(IHttpHandler handler)

            context.RemapHandler(httpHandler);
        }
Exemplo n.º 22
0
        public virtual void PostResolveRequestCache(HttpContextBase context)
        {
            // Match the incoming URL against the route table
            RouteData routeData = RouteCollection.GetRouteData(context);

            // Do nothing if no route found
            if (routeData == null)
            {
                return;
            }

            // If a route was found, get an IHttpHandler from the route's RouteHandler
            IRouteHandler routeHandler = routeData.RouteHandler;

            if (routeHandler == null)
            {
                throw new InvalidOperationException(
                          String.Format(
                              CultureInfo.CurrentCulture,
                              SR.GetString(SR.UrlRoutingModule_NoRouteHandler)));
            }

            // This is a special IRouteHandler that tells the routing module to stop processing
            // routes and to let the fallback handler handle the request.
            if (routeHandler is StopRoutingHandler)
            {
                return;
            }

            RequestContext requestContext = new RequestContext(context, routeData);

            // Dev10 766875	Adding RouteData to HttpContext
            context.Request.RequestContext = requestContext;

            IHttpHandler httpHandler = routeHandler.GetHttpHandler(requestContext);

            if (httpHandler == null)
            {
                throw new InvalidOperationException(
                          String.Format(
                              CultureInfo.CurrentUICulture,
                              SR.GetString(SR.UrlRoutingModule_NoHttpHandler),
                              routeHandler.GetType()));
            }

            if (httpHandler is UrlAuthFailureHandler)
            {
                if (FormsAuthenticationModule.FormsAuthRequired)
                {
                    UrlAuthorizationModule.ReportUrlAuthorizationFailure(HttpContext.Current, this);
                    return;
                }
                else
                {
                    throw new HttpException(401, SR.GetString(SR.Assess_Denied_Description3));
                }
            }

            // Remap IIS7 to our handler
            context.RemapHandler(httpHandler);
        }
 /// <summary>
 /// Provides the object that processes the request.
 /// </summary>
 /// <param name="requestContext">An object that encapsulates information about the request.</param>
 /// <returns>
 /// An object that processes the request.
 /// </returns>
 public IHttpHandler GetHttpHandler(RequestContext requestContext)
 {
     Decorate(requestContext);
     return(innerHandler.GetHttpHandler(requestContext));
 }
 public virtual IHttpHandler GetHttpHandler(RequestContext requestContext)
 {
     AddFormat(requestContext.RouteData, requestContext.HttpContext.Request.AcceptTypes);
     return(proxiedHandler.GetHttpHandler(requestContext));
 }