3

Wherever I use SPUtility.Redirect in my code it works ok for the user but i see a thread abort exception in the ULS logs, the message starts with:

"ExceptionType: 'ThreadAbortException' ExceptionMessage: 'Thread was being aborted.')"

Then a few lines later in ULS i see a host of request not disposed entries starting wtih:

"An SPRequest object was not disposed before the end of this thread"

I have seen other poeple reporting the ThreadAbortException on the internet, but no one has been able to explain why this happens, or how to use SPUtility.Redirect in such a way that the exception isn't thrown. Whilst Response.Redirect(url,false) doesn't raise an exception, i still see the entries reporting that the SPRequest wasn't disposed properly. Hope you can help

5

There's an answer on technet which explains it pretty well:

Hello!

When request is being redirected, the HttpResponse.End() method is called. The given method, in turn, calls

Thread.CurrentThread.Abort(new HttpApplication.CancelModuleException(false));

The Thread.Abort method raises ThreadAbortException in the thread where it is invoked to begin the process of terminating the thread. I mentioned about that in my blog post. So it's normal behavior.

Try to use SPRedirectFlags.DoNotEndResponse when calling SPUtility.Redirect().

1
  • Thank you for this, the correct solution and an explanation of the issue. I couldn't ask for more. Edit: I know this is just pointing to another article but Google brought me here.
    – Vinnyq12
    Jul 5 '13 at 8:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.