Custom 404 and 500 error pages, URL address does not redirect (ii)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.