Try our conversational search powered by Generative AI!

Magnus Rahl
Jul 27, 2010
  5821
(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 www.site.com/Footer/Contacts 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.

Template:

   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>

Codebehind:

   1: public partial class RedirectingContainer : TemplatePage
   2: {
   3:     private PageData _redirectTarget = null;
   4:  
   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:     }
  15:  
  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:     }
  23:  
  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);
  35:  
  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.

Variations

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

Comments

Please login to comment.
Latest blogs
Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog

Azure AI Language – Abstractive Summarisation in Optimizely CMS

In this article, I show how the abstraction summarisation feature provided by the Azure AI Language platform, can be used within Optimizely CMS to...

Anil Patel | Apr 18, 2024 | Syndicated blog

Fix your Search & Navigation (Find) indexing job, please

Once upon a time, a colleague asked me to look into a customer database with weird spikes in database log usage. (You might start to wonder why I a...

Quan Mai | Apr 17, 2024 | Syndicated blog

The A/A Test: What You Need to Know

Sure, we all know what an A/B test can do. But what is an A/A test? How is it different? With an A/B test, we know that we can take a webpage (our...

Lindsey Rogers | Apr 15, 2024

.Net Core Timezone ID's Windows vs Linux

Hey all, First post here and I would like to talk about Timezone ID's and How Windows and Linux systems use different IDs. We currently run a .NET...

sheider | Apr 15, 2024