The previous article was implemented using a global filter, which can also be handled using HttpApplication.
Reference article:
Http://www.cnblogs.com/dudu/p/aspnet_custom_error.html
The first step is exactly the same as the first step in the previous article.
The second step starts with:
Add this method to the Mvcapplication class in Global.asax:
/// <summary> ///When an exception occurs, the application is bound to come in here, and when it does, it returns a 404 error page. /// </summary> protected voidApplication_Error () {Exception LastError=Server.GetLastError (); if(LastError! =NULL) {writerexception ( This. Context, LastError); Response.statuscode=404; Server.ClearError (); } } /// <summary> ///writes exception information. /// </summary> /// <param name= "context" ></param> /// <param name= "Exception" ></param> Private Static voidWriterexception (HttpContext context, Exception Exception) {varLogger =LoggerFactory.Current.Create (); ObjectURI =context. Request.url; stringURL =string. Empty; if(URI! =NULL) {URL=URI. ToString (); } varex =exception. GetBaseException (); varText =NewStringBuilder (); Text. Appendline ("Exception Address:"+URL); Text. Appendline ("Exception Information:"+Ex. Message); Logger. Fatal (ex, text. ToString ()); }
Complete.
Custom 404 and 500 error pages, URL address does not redirect (ii)