Skip to main content

Posts

Showing posts with the label Application Errors

Page Error method

How to use the Page_Error method The Page_Error event handler provides a way to trap errors that occur at the page level. You can simply display error information (as the sample code to follow does), or you can log the event or perform some other action. Note This example displays detailed error information in the browser only for demonstration purposes. You will want to be cautious when displaying detailed information to the end user of the application, especially when the application is running on the Internet. A more appropriate action would be to display a message to the user notifying them that an error has occurred, and then actually logging the specific error details in the event log. This example throws a null exception, which forces an error to occur in the Page_Load event handler. Follow these steps to create the initial page that will demonstrate using the Page_Error event handler. Follow these steps to add a new file named ...

Handle Errors in Application

Handle Application Errors In Application to avoid the handle Errors and maintain the Errors data use the following code....  FileName: Global.asax void Application_Error(object sender, EventArgs e)     {         // Code that runs when an unhandled error occurs         try         {             string str = Server.MapPath("~/logs/") + MyTime.Now().ToString("MMddyyyyHHmmss.err") ;             Exception objErr = HttpContext.Current.Server.GetLastError().GetBaseException();             System.IO.File.AppendAllText(str, objErr.ToString());             //Response.Redirect("~/ErrorPage.html");         }  ...