Custom Error Page
-
Hi, I am working on how to create an custom error page for application error. I have tried the following code I have one button on a page which generate an error on onClick event e.g. protected void ExceptionButton_Click(object sender, EventArgs e) { throw new Exception("Hello World!"); }I have Added a global.asax file and on Application_Error event i have written the following code: void Application_Error(object sender, EventArgs e) { Message.LastException = Server.GetLastError().GetBaseException(); string message = "Error Caught in Application_Error event\n" + "Error in: " + Request.Url.ToString() + "\nError Message:" +Message.LastException.Message.ToString() + "\nStack Trace:" + Message.LastException.StackTrace.ToString(); } But when i run the application and click on a button I got the error at line " throw new Exception("Hello World!");" My required otput is that instead of showing this error it should display the message that i have given in Application_Error event in global.asax file... but I am not getting an output. Can anybody help me???????
-
Hi, I am working on how to create an custom error page for application error. I have tried the following code I have one button on a page which generate an error on onClick event e.g. protected void ExceptionButton_Click(object sender, EventArgs e) { throw new Exception("Hello World!"); }I have Added a global.asax file and on Application_Error event i have written the following code: void Application_Error(object sender, EventArgs e) { Message.LastException = Server.GetLastError().GetBaseException(); string message = "Error Caught in Application_Error event\n" + "Error in: " + Request.Url.ToString() + "\nError Message:" +Message.LastException.Message.ToString() + "\nStack Trace:" + Message.LastException.StackTrace.ToString(); } But when i run the application and click on a button I got the error at line " throw new Exception("Hello World!");" My required otput is that instead of showing this error it should display the message that i have given in Application_Error event in global.asax file... but I am not getting an output. Can anybody help me???????
are you in debug mode. during debugging, it always shows first chance exceptions. ...
Abhishek Sur My Latest Articles Basics on LINQ and Lambda Expressions
Create .NET Templates