1

I have a problem with a redirect in my code. None of the solutions proposed on the web has worked for me. Basically my code is this (not actual code, only description):

protected void btnCool_Click(object sender, EventArgs e)
{
    GetDataFromInterface();
    GetDataSpecificDataFromDB();
    SaveDataOnSession();
    Response.Redirect("SomePage.aspx", false);
    Context.ApplicationInstance.CompleteRequest();
 }

Everything executes nicely, but after the method executes I am just getting thrown to the login page. In the Output windows of VS I see this: "An exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll but was not handled in user code."

Here is some extra info:

  • I am not using a try catch block.
  • I don't have any UpdatePanels on this page, nor in the master page.
  • Application_Error does not even trigger.
  • I even have a second button that does almost the same thing (brings other data) and redirects successfully to another page (same code)
  • I am not changing anything in the Web.Config during the execution.

Edit: For clarification. That exception is thrown no matter what. The redirect to the desired page does not work (that mean I have a dead part in my app. I can't get to it.). Instead I'm getting thrown out from the application.

Please, please help me out with this one. I really don't have any more leads that I could follow so any suggestion might be helpful.

VictorB
  • 371
  • 1
  • 4
  • 17
  • 2
    have a look at http://stackoverflow.com/questions/2777105/response-redirect-causes-system-threading-threadabortexception – PMC Aug 23 '12 at 14:51
  • I found the problem. It was coming from somewhere else. Thank you for the info. i learned something new! – VictorB Aug 24 '12 at 07:44

3 Answers3

1

Yes, you do.

This is by design

http://support.microsoft.com/kb/312629

podiluska
  • 50,950
  • 7
  • 98
  • 104
1

Yes it is by default. The best practice for this situation is mention below

protected void btnCool_Click(object sender, EventArgs e)
{
    try{
    GetDataFromInterface();
    GetDataSpecificDataFromDB();
    SaveDataOnSession();
    Response.Redirect("SomePage.aspx", false);
    Context.ApplicationInstance.CompleteRequest();
     }
    catch(ThreadAbortException Thrdex)
    {}
    catch(Exception ex)
    {
    //Handle exception
    }
 }
SMK
  • 2,098
  • 2
  • 13
  • 21
1

Ok. I have discovered the problem. It was a classic case of PICNIC. That page did not implement an interface that allowed access to a specific type of users. Well, at least I learned a lot about redirects and exceptions.

Thank you very much for your interest and answers!!

VictorB
  • 371
  • 1
  • 4
  • 17