Take the community feedback survey now.

Gatis Bergšpics
Sep 26, 2011
  15611
(0 votes)

Server.Transfer issue, "Error executing child request for /404."

The goal was to create EPi server operator(administrator) modifiable 404 error page. To do this I created new simple page type called ErrorPageType(with very simple aspx file):

[PageType("633fd95b-d6bd-41e5-bc6b-19bc0247f599",
        Name =
"Error page"
,
        Filename =
"/Templates/Pages/ErrorPage.aspx"
)]
   
public class ErrorPageType : TypedPageData

    {
 
        [
PageTypeProperty(EditCaption = "Error page title",
            SortOrder = 0,
            UniqueValuePerLanguage =
true
,
            Required =
false
,
            Searchable =
false
)]
       
public virtual string PageTitle { get; set
; }
 
        [
PageTypeProperty(EditCaption = "Error page body"
,
            SortOrder = 1,
            UniqueValuePerLanguage =
true
,
            Required =
false
,
            Searchable =
false
)]
       
public virtual string MainBody { get; set
; }
 
    }
<!DOCTYPE …>

<html >

<head id="Head1" runat="server">
   
<title><%= CurrentPage.PageTitle %></title>
</head>
<body>
   
<form id="form1" runat="server">
   
<div>
    
<%= CurrentPage.MainBody %>
   
</div>
   
</form>
</body>
</html>

Whole reason behind using Server.Trasfer(instead of Response.Redirect) is following - SEO(search bots most likely wont follow resource moved to that page hints, or wont display them properly in search results. Web browsers however will and there would not be problems). So to achieve that I created new page in EPi server and called it 404 from previously created page type. I tough that this is it - straight forward, but it turned out it is not so, far from it.

My first approach was:

Server.Transfer("/404");

This resulted in following exception: "Error executing child request for /404." of type HttpException that led me to following blog posts:

http://labs.episerver.com/en/Blogs/Svante-Seleborg/Dates/2008/10/When-a-404-Not-Found-should-be-a-404-Not-Found/

and

http://world.episerver.com/Blogs/Dan-Matthews/Dates/2010/3/A-few-tips-on-UI-Plugins-in-CMS6/

So I tried this(no need to disable friendly URLs, because this still should work):

Server.Transfer("/Templates/Pages/ErrorPage.aspx?id=2421&epslanguage=en");

But it did not change anything, so I made constructor for ErrorPage class similar to one Svante Seleborg suggests to use:

public partial class MyPage : SimplePage
{
  public MyPage() : SimplePage(0, HttpContext.Current.Items["InErrorHandler"] == null ? 0 : PageExtensions.SaveCurrentPage.OptionFlag)
  {
  }
}

This led me to the same exact exception, then in Dan Matthew entry I read something similar with optionFlag only this time he suggested to disable different optionFlag that did not help me either.

Next idea was to just pass integer 65535, I thought that this will disable all options and it did, and Server.Transfer and Server.Execute started to work.

At this point I tough that I even do not know what I'm disabling so I went out to search what options are there,did that following way:

Opened up http://sdk.episerver.com/library/cms6.1/index.aspx and searched for OptionFlag, and I found 14 different result and scratched class names out of them, so at first I tried passing all of then, then removing one by one and result was following:

protected ErrorPage()
          
//  : base(0, 65535) //this works as expected

            :
base(0, 
           
HttpContext.Current.Items["InErrorHandler"] == null
? 0 :
            0
          
// | AntiForgeryValidation.OptionFlag

          
// | CultureSupport.OptionFlag
          
// | LoadCurrentPage.OptionFlag
          
// | CustomPageLink.OptionFlag
          
// | ThemeUtility.OptionFlag
          
// | SiteRedirect.OptionFlag
            |
ContextMenu.OptionFlag //this is the one that needs to be disabled
          
// | SaveCurrentPage.OptionFlag
          
// | ServerTransferBugfix.OptionFlag
          
// | SetupContentRedirect.OptionFlag
          
// | PageVisited.OptionFlag
          
// | PageStatistics.OptionFlag
          
// | PageNotFoundRedirect.OptionFlag
          
// | PageTranslation.OptionFlag
            )
        {
        }

At the end of the day, my code looks something like that:

public void TransferToHttpErrorPage(int httpErrorCode)
{
    Response.Clear();
    Response.StatusCode = 404;
 
   
try

    {
       
HttpContext.Current.Items["InErrorHandler"] = true;
                    
       
var factory = new DataFactory
();
 
       
// get error page reference from start page

       
var startPage = factory.GetPage(PageReference.StartPage);
       
if (startPage != null
)
        {
           
var reference = startPage[string.Format("Error{0}PageReference"
, httpErrorCode)];
           
if (reference != null && reference is PageReference
)
            {
               
var page = factory.GetPage((PageReference
)reference);
                Server.Transfer(page.LinkURL);
               
return
;
            }
        }
                
       
// startPage not found or Error{0}PageReference not found

       
// get error page reference by friendly URL
 
       
object pageReference;
       
if (EPiServer.Global.UrlRewriteProvider.ConvertToInternal(new UrlBuilder(string.Format("/{0}", httpErrorCode)), out
pageReference))
        {
           
var page = factory.GetPage((PageReference
) pageReference);
            Server.Transfer(page.LinkURL);
           
return
;
        }
 
       
// if get this far use static error page

        Server.Transfer(
string.Format("/{0}.htm", httpErrorCode));
    }
   
catch (Exception
ex)
    {
        Response.Write((
string.Format("Http error {0} has occurred"
, httpErrorCode)));
        Response.End();
    }
}

I'm new to EPi Server so I have a question to more experienced EPiServer developers: is this a bug or feature, can someone explain why in order for Server.Transfer(or Server.Execute) to work I need to disable ContextMenu option in page?

I used latest EPi Server CMS 6 R2

Sep 26, 2011

Comments

Please login to comment.
Latest blogs
A day in the life of an Optimizely OMVP - Opticon London 2025

This installment of a day in the life of an Optimizely OMVP gives an in-depth coverage of my trip down to London to attend Opticon London 2025 held...

Graham Carr | Oct 2, 2025

Optimizely Web Experimentation Using Real-Time Segments: A Step-by-Step Guide

  Introduction Personalization has become de facto standard for any digital channel to improve the user's engagement KPI’s.  Personalization uses...

Ratish | Oct 1, 2025 |

Trigger DXP Warmup Locally to Catch Bugs & Performance Issues Early

Here’s our documentation on warmup in DXP : 🔗 https://docs.developers.optimizely.com/digital-experience-platform/docs/warming-up-sites What I didn...

dada | Sep 29, 2025

Creating Opal Tools for Stott Robots Handler

This summer, the Netcel Development team and I took part in Optimizely’s Opal Hackathon. The challenge from Optimizely was to extend Opal’s abiliti...

Mark Stott | Sep 28, 2025

Integrating Commerce Search v3 (Vertex AI) with Optimizely Configured Commerce

Introduction This blog provides a technical guide for integrating Commerce Search v3, which leverages Google Cloud's Vertex AI Search, into an...

Vaibhav | Sep 27, 2025

A day in the life of an Optimizely MVP - Opti Graph Extensions add-on v1.0.0 released

I am pleased to announce that the official v1.0.0 of the Opti Graph Extensions add-on has now been released and is generally available. Refer to my...

Graham Carr | Sep 25, 2025