---
title: "Custom Error Page in Asp.Net Mvc 4"  
description: "In this article, I’m explaining how to create a custom error page and invoke it when an error comes in the application using asp.net mvc 4."  
author: "Sumit Kesarwani"  
published: 2014-09-20  
updated: 2020-02-14  
canonical: https://www.mindstick.com/articles/1498/custom-error-page-in-asp-dot-net-mvc-4  
category: "asp.net mvc"  
tags: ["c#", ".net", "asp.net mvc"]  
reading_time: 2 minutes  

---

# Custom Error Page in Asp.Net Mvc 4

Here In this article, I’m explaining how to create a custom error page and invoke it when an error comes in the application using asp.net MVC 4.\

#### Step 1

Create an empty asp.net MVC 4 project and add a controller named “HomeController” like this:

```
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc; namespace CustomErrorPageMvcApp.Controllers{    public class HomeController : Controller    {        //        // GET:
/Home/         public ActionResult Index()        {           return View();        }     }}
```

#### Step 2

Now add a view to the project named “Index”

```
@{    ViewBag.Title = "Index";} <h2>Index</h2>
```

#### Step 3

Now add a new folder to the project named “Shared” like this:

![customeError1.png](https://www.mindstick.com/mindstickarticle/06179892-e4df-4235-a9f9-4da025cee759/images/04c97a4f-abd9-40d5-976e-6cb12048d0b1.png)

And add a view named “Error” like this:

```
@{    Layout = null;} <!DOCTYPE html><html><head>    <meta name="viewport" content="width=device-width" />    <title>Error</title></head><body>    <hgroup>        <h1>Error.</h1>        <h2>An error occurred while processing your request.</h2>    </hgroup></body></html>
```

##### Step 4

Now add customErrors mode=” On” in the web.config file like this:

![customeError2.png](https://www.mindstick.com/mindstickarticle/06179892-e4df-4235-a9f9-4da025cee759/images/23bc701f-bb20-4117-9aa6-3dc6794309b7.png)

#### Step 5

Now add these codes in the HomeController like this:

```
  [HandleError()]  public ActionResult Index()  {      string temp = Session["temp"].ToString();      return View();  }
```

##### Output

Now run the application:

![customeError3.png](https://www.mindstick.com/mindstickarticle/06179892-e4df-4235-a9f9-4da025cee759/images/81c9b79b-1849-41f4-b3e9-761a55acbc48.png)

The above will come and now press F5 and your custom error page will show:

![customeError4.png](https://www.mindstick.com/mindstickarticle/06179892-e4df-4235-a9f9-4da025cee759/images/f986d1b0-faaa-4325-87fc-ad4453a937b1.png)

---

Original Source: https://www.mindstick.com/articles/1498/custom-error-page-in-asp-dot-net-mvc-4

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
