This question already has an answer here:

We have a habitat application with multi-site. If any error occurred, it has to redirect to error page item of specific site.

We were planning to implement by https://community.sitecore.net/technical_blogs/b/sitecorejohn_blog/posts/handling-exceptions-globally-in-mvc-solutions-using-the-sitecore-asp-net-cms-revisited

but in Habitat while creating a module we are deleting the Global.ascx.cs.

If so, how can we have custom error page.

marked as duplicate by jammykam, maz, Patrick Barron, Richard Seal Nov 7 '17 at 17:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


You have different options:

  • Include Global.asax into one of Habitat project. And copy this file during project publishing.
  • Use HTTP module to handle errors:

1) Add module code to your project

public class ErrorModule : IHttpModule
  public void Init(HttpApplication application)
    application.Error += new EventHandler(application_Error);  
  public void Dispose() { }

  public void application_Error(object sender, EventArgs e)
    //handle error

2) Patch web config to use your module:

  <add  name="ErrorModule" type="YourProject.ErrorModule, YourProject" />

I had the same issue, you can patch the pipeline , the below sample used for 404 but it can be extended to all errors.

 <!-- 404 pipeline processor -->

    <!-- Patch after Sitecore Item Resolver -->
    <processor type="Common.Feature.Errors.Pipelines.HttpRequest.Error404, Common.Feature.Errors"
               patch:after="processor[@type='Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel']" />

        <!-- Sets a 404 status code on the response -->
        <processor type="Common.Feature.Errors.ErrorStatusCode, Common.Feature.Errors" patch:after="*[@type='Sitecore.Pipelines.HttpRequest.EndDiagnostics, Sitecore.Kernel']">



Class will look something like :

public class Error404 : HttpRequestProcessor
    public override void Process(HttpRequestArgs args)
            Assert.ArgumentNotNull(args, "args");


and as Antone mentioned you can keep the global.asax in your main project and change the Inherits to refer your error handling code, regardless of its location.

Hope that will help.

  • In later versions of Sitecore the global.asax has been marked as private. You can't inherit from it anymore. This: sitecore.stackexchange.com/questions/221/… - is a much better solution – Richard Seal Nov 7 '17 at 17:31
  • Richard , that solution is basically similar to what i suggested ,i am using it on sitecore 8.2 for 404 & 500 errors. thanks – Naim Alkouki Nov 7 '17 at 17:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.