Simple library that allows you to easily create error pages for common HTTP error and application exceptions.

How to use

Installation:

PM> Install-Package Moveax.Mvc.ErrorHandler

ErrorController and two view templates will be added to your project.

Initializing error hander

Add following code to global.asax.cs:

protected void Application_Error(object sender, System.EventArgs e)
{
    var errorHandler = new MvcApplicationErrorHandler(application: this, exception: this.Server.GetLastError()) {
        EnableHttpReturnCodes = false,
        PassThroughHttp401 = false
    };

    errorHandler.Execute();
}

There are two properties that allow you to configure handler logic.

Adding error pages

Customize ErrorController Default view and/or add new actions and views for other errors. Just combine prefix "Http" with error code. For example:

public ActionResult Http401(ErrorDescription errorDescription)
{
    return this.View();
}

Any application exceptions should be processed in Default() action.

You can add logging code etc into HandleError() method that will be invoked for every error.

Last edited Sep 29, 2013 at 5:53 PM by AndreyDotNet, version 3