Export (0) Print
Expand All

HttpServerUtility.Transfer Method (String, Boolean)

.NET Framework 1.1

Terminates execution of the current page and begins execution of a new page using the specified URL path to the page. Specifies whether to clear the QueryString and Form collections.

[Visual Basic]
Overloads Public Sub Transfer( _
   ByVal path As String, _
   ByVal preserveForm As Boolean _
)
[C#]
public void Transfer(
 string path,
 bool preserveForm
);
[C++]
public: void Transfer(
 String* path,
 bool preserveForm
);
[JScript]
public function Transfer(
   path : String,
 preserveForm : Boolean
);

Parameters

path
The URL path of the new page on the server to execute.
preserveForm
If true, the QueryString and Form collections are preserved. If false, they are cleared. The default is false.

Exceptions

Exception Type Condition
HttpException The resource cannot be found.

Remarks

The page transferred to should be another .aspx page. For instance, a transfer to an .asp or .asmx page is not valid.

Transfer calls End which raises a ThreadAbortException exception upon completion.

If you set preserveForm to true and if the enableViewStateMac attribute of the <pages> Element configuration element is true, ASP.NET will raise an exception when Transfer is executed because the view state from the page that calls Transfer is not valid on the destination page. One of the preserved form fields on the calling page is the hidden __VIEWSTATE form field, which holds the view state for the page. When enableViewStateMac is true, ASP.NET runs a message authentication check (MAC) on the view state of the destination page when the page is posted back from the client and the check will fail. For security purposes, you should keep the enableViewStateMac attribute set to true but there are other methods available to transfer Forms data. For more information, including recommended solutions, see article Q316920, "View State is Invalid Error Message When You Use Server.Transfer" in the Microsoft Knowledge Base at http://support.microsoft.com.

Example

The following example executes a new page in the same directory as the current page.

[Visual Basic] 
Server.Transfer("Logon.aspx")
   

[C#] 
Server.Transfer("Logon.aspx");
   

[C++] 
Server->Transfer(S"Logon.aspx");
   

[JScript] 
Server.Transfer("Logon.aspx")
   

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

HttpServerUtility Class | HttpServerUtility Members | System.Web Namespace | HttpServerUtility.Transfer Overload List

Show:
© 2014 Microsoft