Last post Oct 01, 2008 11:46 PM by malcolms
Oct 01, 2008 08:38 AM|shurabhavesh|LINK
I have created a web application in which if requested page does not exists (error - 404), i redirect the user to centralized error page with following code in Application.Error event in global.asax
string strRequestedURLWithQueryString = ((System.Web.HttpApplication)(sender)).Request.Url.AbsoluteUri;
Server.Transfer("~/Error.aspx?RequestedURL=" + Server.UrlEncode(strRequestedURLWithQueryString));
When I run the appication from direct source file (without publishing), above code works fine, however when i deployed the application to the production server (after publishing) it does not takes the user to the page Error.aspx.
Can anyone comment on the same?
Thanks in advance
Oct 01, 2008 10:52 AM|Haissam|LINK
Check below link
Custom Errors in ASP.NET
Oct 01, 2008 11:31 AM|shurabhavesh|LINK
Thnx for ur response.. but i cant implement the alternate was using the customErrors tag in Web.config. If you can make out what other thing i have to do for handling the errors in Application.Error event in Global.asax, then please reply???
I have written a simple code that will print the exact error on the page
void Application_Error(object sender, EventArgs e)
Exception ex = Server.GetLastError().GetBaseException();
protected void Page_Load(object sender, EventArgs e)
int i = 0, j = 10;
float k = j / i;
create a small application with above code, publish website, and then browse published version of default.aspx. you will find than the application_error method that handles Application.Error event not being called.
What can be the problem ??
Please let me know what the problem is, or what am i missing? dont give alternate way...
Oct 01, 2008 12:19 PM|malcolms|LINK
You should move your redirect code from the Application_Error event and leave that solely for logging the error. Configure the redirect of errors in the customErrors section in your web.config file.
<customErrors mode="On" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
Oct 01, 2008 01:12 PM|shurabhavesh|LINK
no malcolm.. sorry.. but that not useful for my requirement..
as i mentioned previously.. i cant use the alternate solution especially the custonError tag in web.config is of no use according to my requirement
so please keep in mind that i want to know what is the problem with the application.error event handles in global.asax file
Oct 01, 2008 11:46 PM|malcolms|LINK
Are you absolutely sure your Application_Error code is not being called? I would be very surprised to find it not being called.
If there is an exception in your application and you have created a global.asax file, the Application_Error event will be raised. My guess is that you're experiencing an error in the Application_Error code. Turn on some tracing and see what is happening
once inside that block of code.