/// <exclude /> public override RouteData GetRouteData(HttpContextBase context) { if (!SystemSetupFacade.IsSystemFirstTimeInitialized) { return(null); } string localPath = context.Request.Url.LocalPath; if (IsPagePreviewPath(localPath) && PagePreviewContext.TryGetPreviewKey(context.Request, out Guid previewKey)) { var page = PagePreviewContext.GetPage(previewKey); if (page == null) { throw new InvalidOperationException("Not preview information found by key: " + previewKey); } return(new RouteData(this, new C1PageRouteHandler(new PageUrlData(page)))); } if (UrlUtils.IsAdminConsoleRequest(localPath) || IsRenderersPath(localPath)) { return(null); } var urlProvider = PageUrls.UrlProvider; string currentUrl = context.Request.Url.OriginalString; UrlKind urlKind; PageUrlData pageUrlData = urlProvider.ParseUrl(currentUrl, out urlKind); if (pageUrlData == null || urlKind == UrlKind.Renderer) { return(null); } var urlSpace = new UrlSpace(context); // Redirecting friendly urls to public urls if (urlKind == UrlKind.Friendly || urlKind == UrlKind.Redirect || urlKind == UrlKind.Internal) { if (pageUrlData.PathInfo == "/") { pageUrlData.PathInfo = null; } string publicUrl = urlProvider.BuildUrl(pageUrlData, UrlKind.Public, urlSpace); if (publicUrl == null) { if (urlKind != UrlKind.Internal) { return(null); } // Rendering internal url if public url is missing } else { return(GetRedirectRoute(publicUrl)); } } Verify.That(urlKind == UrlKind.Public || urlKind == UrlKind.Internal, "Unexpected url kind '{0}", urlKind); bool isPublicUrl = urlKind == UrlKind.Public; if (isPublicUrl) { // If url ends with a trailing slash - doing a redirect. F.e. http://localhost/a/ -> http://localhost/a if (pageUrlData.PathInfo == "/") { pageUrlData.PathInfo = null; return(GetRedirectRoute(urlProvider.BuildUrl(pageUrlData, UrlKind.Public, urlSpace))); } // Checking casing in url, so the same page will not appear as a few pages by a crawler string correctUrl = urlProvider.BuildUrl(pageUrlData, UrlKind.Public, urlSpace); Verify.IsNotNull(correctUrl, "Failed to rebuild a public url from url '{0}'", currentUrl); string originalFilePath = new UrlBuilder(currentUrl).RelativeFilePath; string correctFilePath = new UrlBuilder(correctUrl).RelativeFilePath; string decodedOriginalPath = HttpUtility.UrlDecode(originalFilePath); string decodedCorrectFilePath = HttpUtility.UrlDecode(correctFilePath); if (!urlSpace.ForceRelativeUrls && (originalFilePath.Length != correctFilePath.Length && decodedOriginalPath != correctFilePath && decodedOriginalPath != decodedCorrectFilePath) || (string.Compare(originalFilePath, correctFilePath, false, CultureInfo.InvariantCulture) != 0 && string.Compare(originalFilePath, correctFilePath, true, CultureInfo.InvariantCulture) == 0) && decodedOriginalPath != decodedCorrectFilePath) { // redirect to a url with right casing return(GetRedirectRoute(correctUrl)); } } // GetRouteData may be executed multiple times if (!context.Items.Contains(HttpContextItem_C1PageUrl)) { PageUrlData = pageUrlData; } var data = new RouteData(this, new C1PageRouteHandler(pageUrlData)); data.Values.Add(RouteData_PageUrl, pageUrlData); return(data); }
private void InitializeFromHttpContextInternal() { HttpContext httpContext = HttpContext.Current; var request = httpContext.Request; var response = httpContext.Response; ProfilingEnabled = request.Url.OriginalString.Contains("c1mode=perf"); if (ProfilingEnabled) { if (!UserValidationFacade.IsLoggedIn()) { string loginUrl = GetLoginRedirectUrl(request.RawUrl); response.Write(@"You must be logged into <a href=""" + loginUrl + @""">C1 console</a> to have the performance view enabled"); response.End(); // throws ThreadAbortException return; } Profiler.BeginProfiling(); _pagePerfMeasuring = Profiler.Measure("C1 Page"); } PreviewMode = PagePreviewContext.TryGetPreviewKey(request, out _previewKey); if (PreviewMode) { Page = PagePreviewContext.GetPage(_previewKey); C1PageRoute.PageUrlData = new PageUrlData(Page); PageRenderer.RenderingReason = PagePreviewContext.GetRenderingReason(_previewKey); } else { PageUrlData pageUrl = C1PageRoute.PageUrlData ?? PageUrls.UrlProvider.ParseInternalUrl(request.Url.OriginalString); Page = pageUrl.GetPage(); _cachedUrl = request.Url.PathAndQuery; PageRenderer.RenderingReason = new UrlSpace(httpContext).ForceRelativeUrls ? RenderingReason.C1ConsoleBrowserPageView : RenderingReason.PageView; } ValidateViewUnpublishedRequest(httpContext); if (Page == null) { throw new HttpException(404, "Page not found - either this page has not been published yet or it has been deleted."); } if (Page.DataSourceId.PublicationScope != PublicationScope.Published) { response.Cache.SetCacheability(HttpCacheability.NoCache); CachingDisabled = true; } PageRenderer.CurrentPage = Page; var culture = Page.DataSourceId.LocaleScope; _dataScope = new DataScope(Page.DataSourceId.PublicationScope, culture); Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = culture; var pagePlaceholderContents = GetPagePlaceholderContents(); PageContentToRender = new PageContentToRender(Page, pagePlaceholderContents, PreviewMode); AttachRendererToAspNetPage(httpContext); }