Server.Transfer and System.Threading.ThreadAbortEx

2019-07-24 06:44发布

问题:

See http://support.microsoft.com/kb/312629/EN-US/

I am using reponse.direct in my app as well and I am not getting the exception. The workaround that the knowledge base article suggests (Server.Execute) does not work for me. I am getting lots of javascript exceptions from the Ajax Toolkit on the target page if I use Server.Execute, and I did not dig into the cause.

My question - what arguments do you see against just swallowing the exception as a 'known limitation' and moving on?

My reason for using Server.Transfer in this one very specific case is that I want to mask the (real) target url of the page that is actually executing. It works pretty well, except for this exception (that the user never sees).

回答1:

Make sure you are not calling Server.Transfer() within an exception handler (try..catch/finally).

Edit:

Server.Transfer always raises ThreadAbortException upon completion. If you wrap it in an exception handler you should trap for explicit exception types instead of just 'Exception'.

See the help for Server.Transfer on MSDN. Here is info about ThreadAbortException