Share via


Behavior of HttpServerUtility::Transfer in v1.0 vs v1.1

A while back I had a customer complain that their web form application broke when they migrated from v1.0 to v1.1 of the .NET Framework.  Turns out they utilized HttpServerUtility::Transfer (or more commonly in a Page class, Server.Transfer) and had some logic that relied on the presence or absence of form and query string variables.  If we look at the definition for HttpServerUtility and then look at the Transfer method, we’ll see there are two overloads:

 public void Transfer(string);
public void Transfer(string, bool);

Both of these methods will stop the execution of the current page and begin the execution of the new page that is passed in the string parameter (path).  In the second overload, the boolean parameter (preserveForm) specifies whether to preserve the QueryString and Form collections.  It is the documentation for this overload that is a bit misleading.  For the preserveForm parameter it states:

preserveForm
If true, the QueryString and Form collections are preserved. If false, they are cleared. The default is false.

But the concept of a default doesn’t really apply in this case.  If you don’t specify the parameter you are in fact calling the other overload.  In v1.0, the end result was that if you called the first overload, the QueryString and Form collections were not preserved.  In v1.1, they are.  In fact in trying to reproduce and investigate this for my customer, I looked to the actual implementation in the Framework and in v1.0 the first overload basically calls the second, passing false for preserveForm.  In v1.1 it passes true.

I’ve got a note into (hopefully) the right folks to get the documentation fixed, but in the meantime I’d do what I ultimately recommended to the developer that brought this to my attention – be explicit and pass true or false.

Comments