Geta / SEO.Sitemaps

Search engine sitemaps.xml for EPiServer CMS
Apache License 2.0
28 stars 42 forks source link

Search Engine Sitemap Settings returns 404 - Language Fallback issue #150

Open trouden opened 3 years ago

trouden commented 3 years ago

Our setup is as follows:

.Net Framework 4.7.2
Episerver.CMS 11.20.5
Episerver.Commerce 13.30
Geta.SEO.Sitemaps 4.0.0
Geta.SEO.Sitemaps.Commerce 4.0.0

When using the domain of website 2 and trying to configure the search engine sitemap settings we receive a 404. When using the domain of website 1 everything works fine.

This all is due to the AdminManageSiteMap inheriting from the SimplePage class, which inherits from the PageBase. I do not know why this is the case, as the settings page is not a real episerver page.

In the OnInit(EventArgs e) method of the PageBase cache policies are being set in this.SetCachePolicy();

The method does the following:

protected virtual void SetCachePolicy() => this.Locate.Advanced.GetInstance<OutputCacheHandler>().SetCachePolicy(PrincipalInfo.CurrentPrincipal, (ContentReference) this.CurrentPageLink, (HttpContextBase) new HttpContextWrapper(this.Context), Settings.Instance, this.CurrentPage != null ? this.CurrentPage.StopPublish : new DateTime?(DateTime.MaxValue));

Here the issue is the CurrentPage is being called, this is resolved by the LoadCurrentPage class which does the following:

    public virtual PageData CurrentPage
    {
      get
      {
        if (this._pageData == null && PageReference.IsValue(this.Page.CurrentPageLink))
        {
          LoaderOptions loaderOptions = new LoaderOptions();
          loaderOptions.Add<LanguageLoaderOption>(this.EnableMasterLanguageFallback ? LanguageLoaderOption.FallbackWithMaster() : LanguageLoaderOption.Fallback());
          this._pageData = this.Page.GetPage(this.Page.CurrentPageLink, loaderOptions);
          if (this._pageData == null || !this.EnableLoadPageWithoutTemplate && !ServiceLocator.Current.GetInstance<TemplateResolver>().HasPageTemplate(this._pageData) || !this.IsRoutable(this._pageData))
          {
            this.Page.Response.Clear();
            ExceptionManager.RenderHttpRuntimeError((Exception) new HttpException(404, "Not Found"));
            this.Page.Response.End();
          }
        }
        return this._pageData;
      }
      set => this._pageData = value;
    }

It tries to retrieve the CurrentPageLink without MasterLanguageFallback, the CurrentPageLink points to the HomePage of the site since AdminManageSiteMap is not a real EpiServer page. Which in our case fails since as mentioned at the beginning browserlanguage is used since no language is included in the path, which in our case is 'en'. The site does not exist in 'en' and so a 404 is returned. This all happens without any error logging so is quite a mystery when we encoutered this at first.

This is related to the issue which was encoutered in #32, except there it was with this.ValidatePageTemplate() which is called later in the OnInit(EventArgs e) method.