Response.Redirect (") inside" using {} "

Assume the following code:

using (SqlConnection conn = new SqlConnection(connectionString))
{
   ...
   using (SqlCommand comm = new SqlCommand(...))
   {
      .. do stuff ..
      if(condition) Response.Redirect("somepage.aspx");

   }
}

Will Response.Redirect () exit from usage blocks cause it to delete all connections?

Or, alternatively, is there a way to exit the usage block that will not result in deletion?

EDIT: I do not want to exit without deleting. I want to know about any pitfalls that might make it not work. - Of course, the prohibition of failures, but then I’m sure that all the facilities are located - the hard way - in this situation

I accepted the answer, which essentially says “I don’t know”, but he very well researched “I don’t know”

Over the course of average time, I will assume that Response.Redirect interrupts the usage statement and code with this in mind. “Not yet proven.”

+3
7

http://msdn.microsoft.com/en-us/library/aa973248.aspx

Response.Redirect WILL NOT finally. , , .

, Using, , . , SharePoint, SP ASP.NET 2.0, , - .

+1

http://msdn.microsoft.com/en-us/library/aa973248.aspx http://msdn.microsoft.com/en-us/magazine/cc163298.aspx:

Response.Redirect WILL NOT finally ( , # "" ). , , .

http://msdn.microsoft.com/en-us/library/system.threading.threadabortexception.aspx:

Abort , ThreadAbortException. ThreadAbortException - , , catch. , finally . , Thread..::. ResetAbort, , , . , Thread..::. . , .

...

+4

Q: , , , ?

A: .

: # ""

+2

Response.Redirect .

. , . , , .. .

Server.Transfer. .

+2

. , , , , . , ..

, - .

0

? .

, , .

0

:

(SqlCommand comm = SqlCommand (...))
{
 ...
  ()
 {

// , ,
     //

break;
   // ;
 }
 // , "" .
}

Response.Redirect();"

?

0

Source: https://habr.com/ru/post/1698090/


All Articles