Try our conversational search powered by Generative AI!

Magnus Rahl
Jul 27, 2010
(0 votes)

Redirecting container page type

I often find it is necessary to use pages just to structure other pages in a site. Many of you have probably at one time or another had a page in your web site root called [Footer menu] or something similar. Editors do this too, to group or tuck away a number of pages that, for example, don’t fit into the menu structure.

Generally you want those container pages to show as little as possible. If some visitor end up on such a page, for example by erasing the last part of the URL when looking at if there were such a page, they would most likely be looking at a pretty empty (ugly, boring…) page.

Using the built-in redirect

So you say “hey, just use the built-in feature to redirect the container to some useful page”. Sure, that works fine. But it’s likely editors will forget to do it from time to time. A different approach is to create a special container page type, and build the redirect mechanism into the page template. I think editors are more likely to remember to use the special page type when creating a container.

The redirecting container page type

I have constructed several different variants of this page type. This is a simple one.


   1: <%@ Page language="c#" Inherits="Acme.Web.Templates.Pages.RedirectingContainer" Codebehind="RedirectingContainer.aspx.cs" %>
   2: <html>
   3:     <head runat="server">
   4:         <title>Redirecting...</title>
   5:     </head>
   6:     <body>
   7:         In view mode this page redirects to <asp:HyperLink runat="server" ID="hlRedirect" />
   8:     </body>
   9: </html>


   1: public partial class RedirectingContainer : TemplatePage
   2: {
   3:     private PageData _redirectTarget = null;
   5:     protected override void OnInit(EventArgs e)
   6:     {
   7:         base.OnInit(e);
   8:         // Detect edit mode by checking for underscore (workpage prefix) in id
   9:         if (!(Request.QueryString["id"] ?? String.Empty).Contains("_"))
  10:         {
  11:             // Perform redirect immediately
  12:             Response.Redirect(RedirectTarget.LinkURL);
  13:         }
  14:     }
  16:     protected override void OnLoad(EventArgs e)
  17:     {
  18:         base.OnLoad(e);
  19:         // Display a link to the redirect page
  20:         hlRedirect.NavigateUrl = RedirectTarget.LinkURL;
  21:         hlRedirect.Text = String.Format("{0} ({1})", RedirectTarget.PageName, RedirectTarget.PageLink.ID);
  22:     }
  24:     protected PageData RedirectTarget
  25:     {
  26:         get
  27:         {
  28:             if (_redirectTarget == null)
  29:             {
  30:                 // Get specified page or parent if empty
  31:                 PageReference pageLink = (PageReference)(CurrentPage["ContainerRedirectTarget"] ?? PageReference.EmptyReference);
  32:                 // Make sure the redirect target is not the current page (avoid infinite loop)
  33:                 pageLink = (PageReference.IsNullOrEmpty(pageLink) || pageLink.Equals(CurrentPage.PageLink)) ? CurrentPage.ParentLink : pageLink;
  34:                 _redirectTarget = DataFactory.Instance.GetPage(pageLink);
  36:             }
  37:             return _redirectTarget;
  38:         }
  39:     }
  40: }

If the page is viewed in edit mode it does not redirect, it merely displays a message (in the form of a link) to where it would redirect in view mode. If the redirect target property is not set it simply redirects to it’s parent.


Some variations of the concept I have used:

  • Make the redirect target property mandatory. Even simpler, but might confuse editors because they feel they must find something meaningful to redirect it to.
  • Use a (possibly configurable) delay before redirecting, and display a “you are now being redirected to…” message. This gives your framework and it’s visitor statistics scripts etc. the possibility to load. The delayed redirect can be accomplished by the meta http-equiv="refresh" directive with delay and url parameters.
  • Use PropertyUrl rather than PropertyPageReference for the redirect property. This obviously makes it possible to redirect to pages outside the site, but beware that it makes it more difficult to detect infinite loops.
Jul 27, 2010


Please login to comment.
Latest blogs
Join the Content Recommendations Work Smarter webinar May 8th 16.00-16.45 CET with expert Aidan Swain

Learn more about Content Recommendations, with Optimizely’s very own Senior Solutions consultant, Aidan Swain . He will discuss best practices and...

Karen McDougall | Apr 12, 2024

Plugin for Identifying and Bulk Deleting Orphaned Missing Properties in Optimizely

I am aware that the Optimizely World community has extensively discussed this topic, with numerous solutions and code snippets available to help...

Adnan Zameer | Apr 11, 2024 | Syndicated blog

Enhancing the Authoring Experience: Extending the LinkItem

The LinkItem field is one of the most demanded properties by the community, allowing editors to effortlessly create and manage links across pages a...

Santiago Morla | Apr 10, 2024 | Syndicated blog

The distinctions between Optimizely Web Experimentation and Optimizely Feature Experimentation

This blog is part of the series - Unlocking the Power of Experimentation: A Marketer's Insight. Let’s dive into Optimizely's powerful experimentati...

Holly Quilter | Apr 9, 2024