Skip to main content

Posts

Showing posts from January, 2015

Custom error page in MVC 4

MVC 4 project has already has an Error.cshtml in Views\Shared folder. In order to use the Error.cshtml, you have to do following steps: 1. Set the customError mode to On inside web.config file under <system.web> element <customErrors mode = " On " /> 2. In the FilterConfig.cs file inside App_Start folder, make sure the filters.Add(new HandleErrorAttribute()) is there.     public class FilterConfig     {         public static void RegisterGlobalFilters( GlobalFilterCollection filters)         {             filters.Add( new HandleErrorAttribute ());         }     } 3. Edit Error.cshtml inside \Views\Shared folder to show error message @mod el System.Web.Mvc. HandleErrorInfo @{     ViewBag.Title = "Error" ;     Layout = "~/Views/Shared/_Layout.cshtml" ; } <div>An error has occurred</div> @ if (Model != null && HttpContext .Current.IsDebuggingEnabled) {     < div >        < p >             < b >Excep