public bool TryFindContent(PublishedContentRequest contentRequest) { //if (contentRequest.Is404 == false) return false; //TODO: Wait until umbraco get rid of this see: https://github.com/umbraco/Umbraco-CMS/blob/d50e49ad37fd5ca7bad2fd6e8fc994f3408ae70c/src/Umbraco.Web/WebBootManager.cs // the 404handlers.config will be removed! // but we need this atm to assemble the redirect id from the umbracoSettings.config <error404></error404> ContentFinderByLegacy404 legacyFinder = new ContentFinderByLegacy404(); bool found = legacyFinder.TryFindContent(contentRequest) && contentRequest.HasPublishedContent; if (found) { // Get culture from browser or application LocalizedRouting router = new LocalizedRouting( applicationContext: ApplicationContext.Current, umbracoContext: contentRequest.RoutingContext.UmbracoContext); // Set the culture for localization contentRequest.Culture = router.TryGetCultureByRequest( request: contentRequest.RoutingContext.UmbracoContext.HttpContext.Request); LogHelper.Debug <ContentFinderByNotFound>("Finder found valid content with id={0}.", () => contentRequest.PublishedContent.Id); LogHelper.Debug <ContentFinderByNotFound>("Finder set status code to 404."); } return(found); }
public bool Execute(string url) { this.redirectID = 0; // Take the umbraco one to assemble the redirect id. // (because some things are internal :-(...) umbraco.handle404 handler = new umbraco.handle404(); if (handler.Execute(url)) { this.redirectID = handler.redirectID; PublishedContentRequest contentRequest = UmbracoContext.Current.PublishedContentRequest; if (contentRequest == null) { return(false); } LocalizedRouting router = new LocalizedRouting( applicationContext: contentRequest.RoutingContext.UmbracoContext.Application, umbracoContext: contentRequest.RoutingContext.UmbracoContext); HttpContext context = HttpContext.Current; if (context == null) { return(false); } HttpRequestWrapper request = new HttpRequestWrapper( httpRequest: context.Request); CultureInfo culture = router.TryGetCultureByRequest( request: request); // Set correct culture Thread.CurrentThread.CurrentUICulture = culture; Thread.CurrentThread.CurrentCulture = culture; contentRequest.Culture = culture; // Do the redirect return(true); } return(false); }