public void AddRouteHandler(IRouteHandler RouteHandler) { Type type; MethodInfo[] mis; RouteAttribute attribute; if (RouteHandler == null) { throw new ArgumentNullException(nameof(RouteHandler)); } type = RouteHandler.GetType(); mis = type.GetMethods(BindingFlags.Public | BindingFlags.Instance); foreach (MethodInfo mi in mis) { attribute = mi.GetCustomAttribute <RouteAttribute>(); if (attribute == null) { continue; } BindRoute(RouteHandler, mi, attribute.Method, routeParser.GetPattern(attribute.URL)); } }
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); }
/// <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"); }
protected virtual void RegisterDefaultRoutes( RouteCollection routes, IRouteHandler portalRouteHandler, IEmbeddedResourceRouteHandler embeddedResourceRouteHandler, IEmbeddedResourceRouteHandler scriptHandler) { routes.Add(portalRouteHandler.GetType().FullName, new Route("{*path}", portalRouteHandler)); }
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); }
protected override void RegisterDefaultRoutes( RouteCollection routes, IRouteHandler portalRouteHandler, IEmbeddedResourceRouteHandler embeddedResourceRouteHandler, IEmbeddedResourceRouteHandler scriptHandler) { // swap out the PortalRouteHandler with a custom dependency (keeping the base script handler) var portalRouteHandlerAdx = new Adxstudio.Xrm.Web.Routing.PortalRouteHandler(PortalName); if (CdnEnabled) { var route = new Route("{cdn}/{*path}", null, new RouteValueDictionary(new { cdn = "cdn" }), portalRouteHandlerAdx); routes.Add(portalRouteHandler.GetType().FullName + ",cdn", route); } base.RegisterDefaultRoutes(routes, portalRouteHandlerAdx, embeddedResourceRouteHandler, scriptHandler); }
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); }
public RouteBuilder(IRouteHandler routeHandler, string httpMethod) { _routeHandler = routeHandler; _routeHandlerType = routeHandler.GetType(); _httpMethod = httpMethod; }
// [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); }
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); }
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); } } } }