1. The Server. Transfer jumps to the page and throws an exception: the thread is being terminated ,.

Source: Internet
Author: User

1. The Server. Transfer jumps to the page and throws an exception: the thread is being terminated ,.

When you insert data to the database and use Server. Transfer to jump back to this page today, an exception is thrown:Terminating thread

Ry {if (0 = String. compare (Password. text. trim (), ConfirmPassword. text. trim () // enter the same password twice {MembershipUser mu = Membership. createUser (UserName. text, Password. text); // Add a registered user Roles. addUserToRole (UserName. text, "worker"); // Add the role String strConn = "server = .; database = ComInfo; integrated security = true; "; // connection string SqlConnection conn = new SqlConnection (strConn); // create a database connection conn. open (); // Open the connection String PassUserid = Request. queryString ["C_Id"]; String userid = mu. providerUserKey. toString (); // obtain the registration ID SqlCommand cmd = new SqlCommand ("insert into Emp (E_Name, E_Sex, E_Position, E_Organisation, E_Address, E_Phone, C_Id, User_Id) values ("+" '"+ UserName. text. trim () + "'," + "'" + edt_sex.Text.Trim () + "'," + "'" + edt_pos.Text.Trim () + "', "+" '"+ edt_dep.Text.Trim () +"', "+" '"+ edt_address.Text.Trim () +"', "+ "'" + Edt_phone.Text.Trim () + "'," + "'" + PassUserid + "', "+ // company ID" '"+ userid +"' "+ // user registration ID") ", conn); // SQL statement, add data cmd to the Emp table. executeNonQuery (); conn. close (); Server. transfer ("~ /User/Imformation. aspx ") ;}} else Response. Write (" <script> window. alert ('two input passwords are different! '); </Script> ");} catch (Exception ex) {Response. write ("<script> window. confirm ('"+ ex. message. toString () + "'); </script> ");}

Cause:Server. the execution of Transfer will call Response internally. end: switches the execution to the Application_EndRequest event in the event pipeline of the application, and throws a ThreadAbortException exception. The exception message is "suspending the thread ".

Solution:Put the Server. Transfer statement in finally, and no exception is thrown.

        finally        {            Server.Transfer("~/User/Imformation.aspx");        }

 




The ServerTransfer () method is used to transfer the value of page jumps.

That...

First, you need to know that the Server. Transfer () page value is not good

If you have to use Transfer

The Transfer method retains the QueryString and Form sets.
You can directly retrieve QueryString and Form from B.

The page variable is obtained by forcibly converting Context. Handler to the class of a page

SystemThreadingThreadAbortException: The thread is being aborted.

Response is not called in the thread.
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.