Last post Sep 20, 2011 07:24 PM by rstrahl
Sep 16, 2011 02:53 PM|kanprad|LINK
I am caching a page with dependency on XML file. Basically if the user is not logged, the page should not be shown and the user should be redirected to a login page.
inside the HttpValidationStatus handler I have code like
based on a cookie value (I had to use cookie because session is inaccessible inside the handler).
This line is throwing an exception:
System.Threading.ThreadAbortException: Thread was being aborted.
context.Request seems to be working fine. So why this is not working. Is there an alternative. I don't want to invalidate the request because basically the output never changes unless the XML was changed. But if the user is not logged in, just redirect,
but the page doesn't need to be cached again.
Is there an alternative?
Sep 20, 2011 07:24 PM|rstrahl|LINK
ASP.NET implicitly ends the request when Response.Redirect() is called and that effectively kills the worker thread that serves the current request. Most commonly the problem is that code runs after the redirect that accesses properties of the HttpContext
intrinsic object that are no longer available.
Try making sure that Response.REdirect() is the last code you run before exiting from the code you're running. If stuff needs to happen afterwards you might have to put that on a delegate to throw it onto a separate thread for completion while the main request
thread is killed.
Another alternative is to wrap the Response.Redirect() ins a try/finally block and put any followup code into the finally. The actual exception is harmless - it's a notification more than a real failure so ignoring it is fine as long as you stay away from
the request's intrinsic objects that might have been disposed.
+++ Rick ---