An error happens, and when it happens you want to display something nice to users, here is how.
Go to web.config, find <system.web>
1 2 3 |
<system.web> <customErrors mode="On" /> </system.web> |
Now go to App_Start/FilterConfig.cs, make sure filter is added, as below;
1 2 3 4 |
public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute()); } |
Then go to Views/_Shared, create new view. Example;
1 2 3 4 5 6 7 8 9 10 11 12 |
@model System.Web.Mvc.HandleErrorInfo @{ ViewBag.Title = "PAGE TITLE"; } @section MetaContent { <meta name="robots" content="none" /> } <div class="container"> <h1 class="text-danger">SOME ERROR MSG</h1> <h2 class="text-danger">DESCRIPTION</h2> </div> |