Пример #1
0
        /// <summary>
        /// The code to run if the current Pipeline context is correct for this particular Pipeline Processor.
        /// </summary>
        /// <param name="args"></param>
        protected override void Execute(HttpRequestArgs args)
        {
            if (Sitecore.Context.Item != null)
            {
                Log.Debug($"Constellation.Foundation.PageNotFound PageNotFoundResolver: Found Context Item. Exiting.");
                return;
            }

            if (args.PermissionDenied)
            {
                Log.Debug("Constellation.Foundation.PageNotFound PageNotFoundResolver: Context Item cannot be accessed by the currrent user. Will not serve a 404 to allow Sitecore to redirect to a login page.");
                return;
            }

            if (Sitecore.Context.Site == null || Sitecore.Context.Language == null || Sitecore.Context.Database == null)
            {
                Log.Warn($"Constellation.Foundation.PageNotFound PageNotFoundResolver: Could not execute for: {HttpContext.Current.Request.Url.OriginalString}", this);
                return;
            }

            var page = PageNotFoundRepository.GetPageNotFoundItem(Sitecore.Context.Site, Sitecore.Context.Language, Sitecore.Context.Database);

            if (page == null)
            {
                Log.Warn($"Constellation.Foundation.PageNotFound PageNotFoundResolver: Site {Sitecore.Context.Site.Name} has no valid setting for the NotFoundPageID attribute.", this);
            }

            Sitecore.Context.Item = page;             // assign the 404 page to the context.
        }
        protected override void Execute(HttpRequestArgs args)
        {
            if (Sitecore.Context.Site == null)
            {
                // We can't do anything, exit.
                Log.Debug($"Verndale.Feature.LanguageFallback DefaultSiteLanguageResolver: No context site for {HttpContext.Current.Request.Url.OriginalString}", this);
                return;
            }

            // Figure out if the language is in the URL already
            var urlLanguage = GetLanguageFromUrl(args);

            if (urlLanguage != null)
            {
                // and if the supplied language is legal for this site.
                if (IsUrlLanguageValidForSite(urlLanguage))
                {
                    Sitecore.Context.Language = urlLanguage;                     // yup, we're done.
                    return;
                }

                // Language is not supported. We need to 404.
                // We ABSOLUTELY have to redirect here, because this Processor runs BEFORE Item Resolver, so any setting of the
                // context item here will be overwritten by the pipeline, which we don't want.

                SetLanguageToDefaultForSite();                 // This ensures the generated link has the right language.

                var target  = PageNotFoundRepository.GetPageNotFoundItem(Sitecore.Context.Site, Sitecore.Context.Language, Sitecore.Context.Database);
                var options = LinkManager.GetDefaultUrlOptions();
                options.LanguageEmbedding = LanguageEmbedding.Always;                 // force the URL to switch language.

                var url = LinkManager.GetItemUrl(target, options);

                // Perform's a TransferRequest rather than a redirect.
                if (Sitecore.Configuration.Settings.RequestErrors.UseServerSideRedirect)
                {
                    HttpContext.Current.Server.TransferRequest(url);
                }
                else
                {
                    WebUtil.Redirect(url, true);
                }
            }

            // No valid language in the URL, therefore we can force the site's default language
            SetLanguageToDefaultForSite();
        }
Пример #3
0
        protected override void Execute(HttpRequestArgs args)
        {
            if (Sitecore.Context.Item != null)
            {
                Log.Debug($"Verndale.Foundation.PageNotFound PageNotFoundResolver: Found Context Item. Exiting.");
                return;
            }

            if (Sitecore.Context.Site == null || Sitecore.Context.Language == null || Sitecore.Context.Database == null)
            {
                Log.Warn($"Verndale.Foundation.PageNotFound PageNotFoundResolver: Could not execute for: {HttpContext.Current.Request.Url.OriginalString}", this);
                return;
            }

            var page = PageNotFoundRepository.GetPageNotFoundItem(Sitecore.Context.Site, Sitecore.Context.Language, Sitecore.Context.Database);

            if (page == null)
            {
                Log.Warn($"Verndale.Foundation.PageNotFound PageNotFoundResolver: Site {Sitecore.Context.Site.Name} has no valid setting for the NotFoundPageID attribute.", this);
            }

            Sitecore.Context.Item = page;             // assign the 404 page to the context.
        }