Application_Error Exception Handling

Source: Internet
Author: User

/// <summary>        ///Catching exceptions/// </summary>        protected voidApplication_Error () {//get an instance of the previous exception            varex =Server.GetLastError ().            GetBaseException (); {                varSberror =NewStringBuilder (); Sberror.appendformat ("URL originalstring:{0}\r\n", Request.Url.OriginalString); Sberror.appendformat ("URL pathandquery:{0}\r\n", Request.Url.PathAndQuery); Sberror.appendformat ("URL. ToString (): {0}\r\n", Request.Url.ToString ()); Sberror.appendformat ("URL absoluteuri:{0}\r\n", Request.Url.AbsoluteUri); varquery = (string. IsNullOrEmpty (Request.Url.Query)?"":"?"+Request.Url.Query); Sberror.appendformat ("query:{0}\r\n", query); Sberror.appendformat ("time of occurrence: {0}\r\n", DateTime.Now.ToString ("yyyy-mm-dd HH:mm:ss FFFF")); Sberror.appendformat ("exception ip:{0}\r\n", PcHelper.GetInstance.GetIp ()); Sberror.appendformat ("Exception Computer name: {0}\r\n", PcHelper.GetInstance.GetUserHostName ()); Sberror.appendformat ("Browser: {0}\r\n", PcHelper.GetInstance.GetBrowser ()); varUrlrefer =string.                Empty; if(Request.urlreferrer! =NULL) {Urlrefer=Request.UrlReferrer.OriginalString; } Sberror.appendformat ("Urlrefer originalstring:{0}\r\n", Urlrefer); Sberror.appendformat ("Error Time: {0}\r\n", DateTime.Now.ToString ("yyyy-mm-dd HH:mm:ss FFFF")); Sberror.appendformat ("Error File: {0}\r\n", ex.                Source); Sberror.appendformat ("error message: {0}\r\n", ex.                Message); Sberror.appendformat ("method that caused the error: {0}\r\n", ex.                TargetSite); Sberror.appendformat ("Error Stack: {0}\r\n", ex.                StackTrace); //logging errors to the logFileHelper.GetInstance.WriteToFile (Server.MapPath (Commonconst.errorlogpath), sberror.tostring ()); }        }

Application_Error Exception Handling

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.