HttpServerUtility.Transfer HttpServerUtility.Transfer HttpServerUtility.Transfer HttpServerUtility.Transfer Method

定義

結束目前網頁的執行,開始針對目前的要求執行新網頁。Terminates execution of the current page and starts execution of a new page for the current request.

多載

Transfer(String) Transfer(String) Transfer(String) Transfer(String)

針對目前的要求結束目前網頁的執行,並使用指定的網頁 URL 路徑開始執行新網頁。For the current request, terminates execution of the current page and starts execution of a new page by using the specified URL path of the page.

Transfer(String, Boolean) Transfer(String, Boolean) Transfer(String, Boolean) Transfer(String, Boolean)

結束目前網頁的執行,並使用指定的網頁 URL 路徑開始執行新網頁。Terminates execution of the current page and starts execution of a new page by using the specified URL path of the page. 指定是否要清除 QueryStringForm 集合。Specifies whether to clear the QueryString and Form collections.

Transfer(IHttpHandler, Boolean) Transfer(IHttpHandler, Boolean) Transfer(IHttpHandler, Boolean) Transfer(IHttpHandler, Boolean)

結束目前網頁的執行,並使用實作 IHttpHandler 介面的自訂 HTTP 處理常式開始執行新要求,以及指定是否要清除 QueryStringForm 集合。Terminates execution of the current page and starts execution of a new request by using a custom HTTP handler that implements the IHttpHandler interface and specifies whether to clear the QueryString and Form collections.

Transfer(String) Transfer(String) Transfer(String) Transfer(String)

針對目前的要求結束目前網頁的執行,並使用指定的網頁 URL 路徑開始執行新網頁。For the current request, terminates execution of the current page and starts execution of a new page by using the specified URL path of the page.

public:
 void Transfer(System::String ^ path);
public void Transfer (string path);
member this.Transfer : string -> unit
Public Sub Transfer (path As String)

參數

path
String String String String

要在伺服器上執行之新網頁的 URL 路徑。The URL path of the new page on the server to execute.

備註

[傳送到] 頁面上應該是另一個.aspx 頁面。The page transferred to should be another .aspx page. 比方說,傳輸至.asp 或.asmx 頁面不是有效的。For instance, a transfer to an .asp or .asmx page is not valid. Transfer方法會保留QueryStringForm集合。The Transfer method preserves the QueryString and Form collections.

Transfer 呼叫End,哪些則會擲回ThreadAbortException完成時的例外狀況。Transfer calls End, which throws a ThreadAbortException exception upon completion.

ASP.NET 不會驗證目前的使用者已獲授權檢視所提供的資源Transfer方法。ASP.NET does not verify that the current user is authorized to view the resource delivered by the Transfer method. 雖然 ASP.NET 授權和驗證邏輯執行原始的資源處理常式會在呼叫之前,ASP.NET 就會直接呼叫所指定的處理常式Transfer方法且不重新驗證和授權的邏輯執行新的資源。Although the ASP.NET authorization and authentication logic runs before the original resource handler is called, ASP.NET directly calls the handler indicated by the Transfer method and does not rerun authentication and authorization logic for the new resource. 如果您的應用程式安全性原則需要用戶端具有適當的授權,才能存取資源,應用程式應該強制重新授權,或提供自訂的存取控制機制。If your application's security policy requires clients to have appropriate authorization to access the resource, the application should force reauthorization or provide a custom access-control mechanism.

您可以使用,以強制重新授權Redirect方法,而非Transfer方法。You can force reauthorization by using the Redirect method instead of the Transfer method. Redirect方法會執行用戶端重新導向瀏覽器要求新的資源。The Redirect method performs a client-side redirect in which the browser requests the new resource. 此重新導向是進入系統的新要求,因為它被必須的 Internet Information Services (IIS) 和 ASP.NET 的安全性原則的所有驗證和授權邏輯。Because this redirect is a new request entering the system, it is subjected to all the authentication and authorization logic of both Internet Information Services (IIS) and ASP.NET security policy.

您可以確認使用者已透過合併自訂授權使用的方法,檢視資源的權限IsInRole方法,應用程式會呼叫再Transfer方法。You can verify that the user has permission to view the resource by incorporating a custom authorization method that uses the IsInRole method before the application calls the Transfer method.

Transfer(String, Boolean) Transfer(String, Boolean) Transfer(String, Boolean) Transfer(String, Boolean)

結束目前網頁的執行,並使用指定的網頁 URL 路徑開始執行新網頁。Terminates execution of the current page and starts execution of a new page by using the specified URL path of the page. 指定是否要清除 QueryStringForm 集合。Specifies whether to clear the QueryString and Form collections.

public:
 void Transfer(System::String ^ path, bool preserveForm);
public void Transfer (string path, bool preserveForm);
member this.Transfer : string * bool -> unit
Public Sub Transfer (path As String, preserveForm As Boolean)

參數

path
String String String String

要在伺服器上執行之新網頁的 URL 路徑。The URL path of the new page on the server to execute.

preserveForm
Boolean Boolean Boolean Boolean

true 表示保留 QueryStringForm 集合,而 false 表示清除 QueryStringForm 集合。true to preserve the QueryString and Form collections; false to clear the QueryString and Form collections.

例外狀況

目前的網頁要求為回呼。The current page request is a callback.

範例

下列範例會執行目前的頁面相同目錄中新的頁面。The following example executes a new page in the same directory as the current page.

Server.Transfer("Logon.aspx", true);

Server.Transfer("Logon.aspx", true)

備註

[傳送到] 頁面上應該是另一個.aspx 頁面。The page transferred to should be another .aspx page. 比方說,傳輸至.asp 或.asmx 頁面不是有效的。For instance, a transfer to an .asp or .asmx page is not valid.

Transfer 呼叫End,哪些則會擲回ThreadAbortException完成時的例外狀況。Transfer calls End, which throws a ThreadAbortException exception upon completion.

如果您設定preserveForm參數來true,[目標] 頁面將能夠存取前一頁的檢視狀態使用PreviousPage屬性。If you set the preserveForm parameter to true, the target page will be able to access the view state of the previous page by using the PreviousPage property.

基於安全考量,您應該保留enableViewStateMac屬性設為trueFor security purposes, you should keep the enableViewStateMac attribute set to true. ASP.NET 不會驗證目前的使用者已獲授權檢視所提供的資源Transfer方法。ASP.NET does not verify that the current user is authorized to view the resource delivered by the Transfer method. 雖然 ASP.NET 授權和驗證邏輯執行原始的資源處理常式會在呼叫之前,ASP.NET 就會直接呼叫所指定的處理常式Transfer方法且不重新驗證和授權的邏輯執行新的資源。Although the ASP.NET authorization and authentication logic runs before the original resource handler is called, ASP.NET directly calls the handler indicated by the Transfer method and does not rerun authentication and authorization logic for the new resource. 如果您的應用程式安全性原則需要用戶端具有適當的授權,才能存取資源,應用程式應該強制重新授權,或提供自訂的存取控制機制。If your application's security policy requires clients to have appropriate authorization to access the resource, the application should force reauthorization or provide a custom access-control mechanism.

您可以使用,以強制重新授權Redirect方法,而非Transfer方法。You can force reauthorization by using the Redirect method instead of the Transfer method. Redirect方法會執行用戶端重新導向瀏覽器要求新的資源。The Redirect method performs a client-side redirect in which the browser requests the new resource. 此重新導向是進入系統的新要求,因為它被必須的 Internet Information Services (IIS) 和 ASP.NET 的安全性原則的所有驗證和授權邏輯。Because this redirect is a new request entering the system, it is subjected to all the authentication and authorization logic of both Internet Information Services (IIS) and ASP.NET security policy.

您可以確認使用者已透過合併自訂授權使用的方法,檢視資源的權限IsInRole方法,應用程式會呼叫再Transfer方法。You can verify that the user has permission to view the resource by incorporating a custom authorization method that uses the IsInRole method before the application calls the Transfer method.

Transfer(IHttpHandler, Boolean) Transfer(IHttpHandler, Boolean) Transfer(IHttpHandler, Boolean) Transfer(IHttpHandler, Boolean)

結束目前網頁的執行,並使用實作 IHttpHandler 介面的自訂 HTTP 處理常式開始執行新要求,以及指定是否要清除 QueryStringForm 集合。Terminates execution of the current page and starts execution of a new request by using a custom HTTP handler that implements the IHttpHandler interface and specifies whether to clear the QueryString and Form collections.

public:
 void Transfer(System::Web::IHttpHandler ^ handler, bool preserveForm);
public void Transfer (System.Web.IHttpHandler handler, bool preserveForm);
member this.Transfer : System.Web.IHttpHandler * bool -> unit
Public Sub Transfer (handler As IHttpHandler, preserveForm As Boolean)

參數

handler
IHttpHandler IHttpHandler IHttpHandler IHttpHandler

HTTP 處理常式,實作 IHttpHandler,以傳輸目前要求至此。The HTTP handler that implements the IHttpHandler to transfer the current request to.

preserveForm
Boolean Boolean Boolean Boolean

true 表示保留 QueryStringForm 集合,而 false 表示清除 QueryStringForm 集合。true to preserve the QueryString and Form collections; false to clear the QueryString and Form collections.

例外狀況

目前的網頁要求為回呼。The current page request is a callback.

備註

您可以撰寫自訂的 HTTP 處理常式來處理特定的預先定義的類型與 Common Language Specification (CLS) 相容的任何語言的 HTTP 要求。You can write custom HTTP handlers to process specific, predefined types of HTTP requests in any language that is compliant with the Common Language Specification (CLS). HTTP 處理常式類別,而不是傳統的 ASP (也稱為傳統 ASP) 網頁或 ASP.NET 網頁中定義的可執行程式碼會回應下列特定的要求。Executable code that is defined in the HTTP handler classes instead of conventional ASP (also known as classic ASP) pages or ASP.NET pages responds to these specific requests. HTTP 處理常式進行互動的低層級的要求和回應服務的 Web 伺服器正在執行 Internet Information Services (IIS) 及它們提供類似的功能 ISAPI 擴充程式,但具有簡單的程式設計模型。HTTP handlers allow for interacting with the low-level request and response services of a Web server that is running Internet Information Services (IIS), and they provide functionality that is similar to ISAPI extensions but with a simpler programming model.

如果您設定preserveForm參數來true,[目標] 頁面將能夠存取前一頁的檢視狀態使用PreviousPage屬性。If you set the preserveForm parameter to true, the target page will be able to access the view state of the previous page by using the PreviousPage property.

基於安全考量,您應該保留enableViewStateMac屬性設為trueFor security purposes, you should keep the enableViewStateMac attribute set to true. ASP.NET 不會驗證目前的使用者已獲授權檢視所提供的資源Transfer方法。ASP.NET does not verify that the current user is authorized to view the resource delivered by the Transfer method. 雖然 ASP.NET 授權和驗證邏輯執行原始的資源處理常式會在呼叫之前,ASP.NET 就會直接呼叫所指定的處理常式Transfer方法,以及新的執行不會重新執行驗證和授權邏輯資源。Although the ASP.NET authorization and authentication logic runs before the original resource handler is called, ASP.NET directly calls the handler indicated by the Transfer method, and does not rerun authentication and authorization logic for the new resource. 如果您的應用程式的安全性原則需要用戶端具有適當的授權,才能存取資源,應用程式應該強制重新授權,或提供自訂的存取控制機制。If the security policy for your application requires clients to have appropriate authorization to access the resource, the application should force reauthorization or provide a custom access-control mechanism.

您可以使用,以強制重新授權Redirect方法,而非Transfer方法。You can force reauthorization by using the Redirect method instead of the Transfer method. Redirect方法會執行用戶端重新導向瀏覽器要求新的資源。The Redirect method performs a client-side redirect in which the browser requests the new resource. 因為此重新導向新的要求進入系統,所以必須以 IIS 和 ASP.NET 的安全性原則的所有驗證和授權邏輯。Because this redirect is a new request entering the system, it is subjected to all the authentication and authorization logic of both the IIS and ASP.NET security policy.

您可以確認使用者已透過合併自訂授權使用的方法,檢視資源的權限IsInRole方法,應用程式會呼叫再Transfer方法。You can verify that the user has permission to view the resource by incorporating a custom authorization method that uses the IsInRole method before the application calls the Transfer method.

適用於