Reputation: 28964
I have an ASP.NET application using custom errors. There is one error that occurs that I can't seem to get any information about. When the error happens, it does trigger the custom error page, but for some reason it doesn't trigger Page_Error or Application_Error. If I turn CustomErrors Off completely, I get absolutely no feedback at all. The only feedback I ever have gotten up until now is the redirect to the Custom Error Page.
Scenario: ASP.NET WebForms application. One of the pages has an UpdatePanel with a Submit button. The page works fine. But if I walk away for a while (seems to be 30-60 minutes) and then come back and click the Submit button, nothing happens; no error, no response from the page- nothing. I have not been able to get this to happen while running in the Debugger; it only happens when it is hosted in IIS (7.5). [I've seen other SO posts about this issue but none of the suggestions worked for me.]
When the error happens, with CustomErrors=On or RemoteOnly, the redirect to the custom error page works, and with RemoteOnly, from the server, I get no feedback at all, similar to a remote connection with customerrors=off. I was really hoping for the YSOD error page.
I tried trapping the error in Page_Error by logging the errors to a database, but that didn't work either. I know the Page_Error and the DB portion is working because if I change the submit code behind to do a divide by zero, the error is logged in the DB. Also, the divide by zero error will be displayed to the client with customerrors=off, and with it on it will display the custom error page. But removing the divide by zero error, and then waiting 30 mins or so and trying again, the Page_Error code is not hit, even though it does redirect to the custom error page. I then tried moving the code in the Page_Error to Application_Error, but the exact same thing happens. The forced divide by error works but this seemingly timeout related error does not.
So, are there certain errors that can still trigger the redirect to the custom error page, but will not trigger the Application_Error event?
Upvotes: 1
Views: 1342
Reputation: 28964
Thank you John and Sergey! This really was a can of worms. Sergey, you were exactly right- the session timed out. John your idea made me think to look at the Windows Application Event Log rather than trying to track it down in the code. It turned out that my ViewState was expiring when the session timed out, which was set to 20 minutes by default. The exact event log error was:
"Viewstate verification failed. Reason: The viewstate supplied failed integrity check."
Now I was able to manually recycle the app pool and force the error to happen at my leisure which made solving it easier. I wasn't using Session though, at least not on the page in question, so why did this matter? This link was helpful in troubleshooting what was happening.
http://support.microsoft.com/default.aspx?scid=kb;en-us;829743
Buried deep into the article was the following sentence describing a scenario causing the worker process to recycle:
"The application pool is running under an identity other than the Local System account, the Network Service account, or an administrative-level account."
My AppPool is in fact running under a local user account which I created specifically for this purpose. When I changed the AppPool to run with ApplicationPoolIdentity, after recycling the AppPool the ViewState error went away. Then I set the AppPool back to run with the local user account again, gave that account local admin privileges, and this also fixed it. Not wanting to have this user be a local admin, I ended up going with a different solution, which was to generate a machine key for this app so the ViewState MAC is always the same, rather than using the default of auto-generating a new one every time the pool recylces or the session times out. Note this is also what you typically need to do if you have multiple web servers behind a load balancer.
Upvotes: 1