Before doing the project is in each page to deal with the different exception information, a page count down, a lot of try{}catch{} statement block, the entire code structure is not beautiful.
See a post today about using the global application class to help get exception information, using the server. Transfer ("") specifies the page to accept the error, plus the use of server in the Accept error page. GetLastError () Gets the previous exception source.
The Application_Error function in Global.asax is as follows:
protected void Application_Error (object sender, EventArgs e) { //captures all exceptions under the entire solution try { Server.Transfer ("~/error.aspx"); } Catch {}
Error Accept page error.aspx the relevant code for getting exception information is as follows:
Exception ex = Server.GetLastError (). GetBaseException (); Gets the exception source if (ex! = null) { Response.Write (ex. Message); } Clears the previous exception
The test exception code in test page text.aspx is as follows:
Tests whether the exception information was captured //test1 //int userid = Convert.ToInt32 (request["userid"). ToString ()); Test2 String Name = "Aganar";
Run the Test.aspx page, we will see the relevant exception information, we can clearly see that there is no one try{}catch{} statement block exists in the page test.aspx page, we can easily capture the exception information.