I'm not familiar enough with the internals of session writing, but I imagine it has some complexities, as it relies on translating the browser session cookies into a server identification. Additionally, ThreadAbortExceptions do have special considerations in the runtime, which may play in here, I'm not sure.
In any case, Response.Redirect()
has an overload that takes a boolean parameter that lets you specify whether you want to end the thread or not.
Response.Redirect(string url, bool endResponse);
If you call it with endResponse set to "false", it will gracefully finish, rather than calling Thread.Abort()
internally. However, this means it will also execute any code left in the page lifecycle before finishing up.
A good compromise is to call Response.Redirect(url, false)
followed by Application.CompleteRequest()
. This will allow your redirect to happen but also gracefully shut down the current execution context with a minimal amount of additional lifecycle processing.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…