public override RouteData GetRouteData(HttpContextBase httpContext) { PortalRequestContext context = httpContext.GetPortalContext(); if(context.ActivePage != null) { return null; } string pagePath = httpContext.Request.AppRelativeCurrentExecutionFilePath; // Normalize path to the form: /Segment/Segment/Segment pagePath = NormalizePagePath(pagePath); // Search for the page Page page = PageRepository.GetLongestPrefixMatch(pagePath); // If there is no matching page, return null if(page == null) { return null; } // Set the page in the context context.ActivePage = page; // Remove the actual page path and set as the new app-relative path string appRelativePath = pagePath.Substring(page.Path.Length); // Rewrite and reroute the request // TODO: Can HttpContext.RewritePath do what we need? I do want to preserve the old HttpContext for use after routing HttpContextBase rewrittenContext = new RewrittenHttpContext(httpContext, appRelativePath); return RerouteRequest(r => r.GetRouteData(rewrittenContext)); }
public override RouteData GetRouteData(HttpContextBase httpContext) { PortalRequestContext portalRequestContext = httpContext.GetPortalContext(); if(httpContext.HasPortalContext() && portalRequestContext.ActivePortal != null) { return null; // Portal has already been specified, bypass this pre-router } Uri requestUrl = httpContext.Request.Url; PortalPrefix prefix = PortalPrefixRepository.GetLongestPrefixMatch(requestUrl); if(prefix == null || prefix.Portal == null) { return null; } portalRequestContext.ActivePortal = prefix.Portal; portalRequestContext.ActivePortalPrefix = prefix; // Determine the Portal-relative url string portalRelativeUrl = ExtractPortalRelativeUrl(requestUrl, prefix); // Rewrite and re-route the request // TODO: Can HttpContext.RewritePath do what we need? I do want to preserve the old HttpContext for use after routing HttpContextBase rewrittenContext = new RewrittenHttpContext(httpContext, portalRelativeUrl); return RerouteRequest(route => route.GetRouteData(rewrittenContext)); }