More in this section

Forums / Developing with Sitefinity / Redirect to homepage if language page not exists

Redirect to homepage if language page not exists

2 posts, 0 answered
  1. medo
    medo avatar
    9 posts
    22 Nov 2009
    14 Jan 2010
    Link to this post

    I have a multilingual site.
    The switching is done with a custom languagelist selector using images of countryflags.
    The code is based on the sample provided here.

    For the default language I have a Page in dutch. (lets call it AboutUs.aspx)
    De english site does not have this page.
    When I now click in the english flag I get
    /en/AboutUs.aspx but as this page doesn't exist I get the same Dutch content, which is weird in my opinion.
    What I want to achieve is that if the page doesn't exist I get the english Homepage.
    How can I achieve this?

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    12 Sep 2017
    15 Jan 2010
    Link to this post
    Hi medo,

    You can add the following code as a user control to your template. It will redirect all requests to a not existing pages to your default home page.

    protected override void OnPreRender(EventArgs e)
           if (!Page.IsPostBack)
               Guid pageID = new Guid(this.Context.Items["cmspageid"].ToString());
               IList<string> stringList = new List<string>();
               var manager = new CmsManager();
               ICmsPage page = (ICmsPage)manager.GetPage(pageID, true);
               if (page != null)
                   foreach (IPageContent version in page.LanguageVersions.Values)
                       int cult = version.LangID;
                       CultureInfo pageCult = new CultureInfo(cult);
                       string cu = pageCult.Name;
                   CultureInfo culture = CultureInfo.GetCultureInfo(page.LangID);
                   string c = culture.Name;
                   foreach (string st in stringList)
                       if (st != c && !String.IsNullOrEmpty(c))

    You could also implement the logic in custom HttpHanlder.

    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
2 posts, 0 answered