Thursday, December 20, 2012

When trying to replace Response.Redirect with Server.Transfer you will need to handle get variables a different way.

http://shawpnendu.blogspot.com/2010/12/using-servertransfer-how-to-pass-values.html seems to have a pretty good article on it. The write up suggests that this...

Response.Redirect("/search/default.aspx?q=" + q.Value);

 
 

...is most appropriately replaced like so...

HttpContext CurrContext = HttpContext.Current;
CurrContext.Items.Add("q", q.Value);
Server.Transfer("/search/default.aspx");

 
 

...and NOT like so which won't fly...

Server.Transfer("/search/default.aspx?q=" + q.Value);

 
 

Fish variables back out on the other side of the leap like so:

HttpContext CurrContext = HttpContext.Current;
var whatever = CurrContext.Items["q"].ToString()

 
 

This way isn't going to cut it in this implementation.

No comments:

Post a Comment