Why do I get an exception when I run Response.Redirect ()?

I am learning ASP.NET and looking at QueryStrings.

One of the examples I looked at presses a button before forwarding:

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            //throws ThreadAbortException: "Thread was being aborted"
            Response.Redirect("Form2.aspx");
        }
        catch (Exception Ex)
        {
            System.Diagnostics.Debug.WriteLine(Ex.Message);
        }
    }

Why does this throw a ThreadAbortException here? This is normal? Do I have to do something? The exceptions are generally not very good, so I was alarmed when I saw this.

+5
source share
9 answers

This is by design. This article KB article describes the behavior (also for Request.End()and methods Server.Transfer()).

For Response.Redirect()there is overload:

Response.Redirect(String url, bool endResponse)

endResponse = false, ( ).

endResponse = true ( bool), , .

+12

. Server.Transfer() .

, Response.End(), . Rick Strahl , , , .

+3

, , . , , ASP.NET , . ( Response.End , ).

, , , . , ( false), , - , , !

+2

Response.Redirect Response.End , , :

Response.Redirect(url, false);
+2

, . Response.Redirect calls Response.End(), , . , , , TA exc.

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

+1

Redirect(), URL-, Response.End() - ThreadAbort, , /UC .

.. , Redirect(), , , .

0

. , , .

, , , .

0

. . - , , . try/catch/finally , .

, , , , . ( , , , , , .)

0

All Articles