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.