Posts

Showing posts from 2016

ASP.Net MVC: Call your own Custom Error Page in MVC

There are inbuilt option available from MVC to show the error page incase of any error occurred in the application/website but in some cases we need customized error page to show when any error occur. 1. You need to write code on the global.asax file Application_error method.  void Application_Error(Object sender, EventArgs e) { var exception = Server.GetLastError(); if (exception == null) return; int statusCode = (exception.GetType() == typeof(HttpException)) ? ((HttpException)exception).GetHttpCode() : 500; var contextWrapper = new HttpContextWrapper(Context); var errorObject = new ErrorInfo { HttpStatusCode = statusCode, ExceptionMessage = "Error Occured", IsAjaxRequest = contextWrapper.Request.IsAjaxRequest() }; Response.Redirect(String.Format("~/Error/{0}/?responseText={1}", "ErrorView", JsonConvert.SerializeObject(errorObject))); } 2. You need create a controller named errorcontroller and create action named index as...