HttpServerUtility.Execute Method

Definition

在目前要求的內容中執行指定資源的處理常式,並將執行傳回叫用它的網頁。Executes the handler for a specified resource in the context of the current request and returns execution to the page that invoked it.

Overloads

Execute(String)

在目前要求的內容中,執行指定虛擬路徑的處理常式。Executes the handler for the specified virtual path in the context of the current request.

Execute(String, Boolean)

在目前要求的內容中,執行指定虛擬路徑的處理常式,並指定是否清除 QueryStringForm 集合。Executes the handler for the specified virtual path in the context of the current request and specifies whether to clear the QueryString and Form collections.

Execute(String, TextWriter)

在目前要求的內容中,執行指定虛擬路徑的處理常式。Executes the handler for the specified virtual path in the context of the current request. TextWriter 會擷取已執行處理常式的輸出。A TextWriter captures output from the executed handler.

Execute(String, TextWriter, Boolean)

在目前要求的內容中,執行指定虛擬路徑的處理常式。Executes the handler for the specified virtual path in the context of the current request. TextWriter 會擷取網頁的輸出,並且布林參數會指定是否要清除 QueryStringForm 集合。A TextWriter captures output from the page and a Boolean parameter specifies whether to clear the QueryString and Form collections.

Execute(IHttpHandler, TextWriter, Boolean)

在目前要求的內容中,執行指定虛擬路徑的處理常式。Executes the handler for the specified virtual path in the context of the current request. TextWriter 會擷取已執行處理常式的輸出,並且布林參數會指定是否要清除 QueryStringForm 集合。A TextWriter captures output from the executed handler and a Boolean parameter specifies whether to clear the QueryString and Form collections.

Execute(String)

在目前要求的內容中,執行指定虛擬路徑的處理常式。Executes the handler for the specified virtual path in the context of the current request.

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

Parameters

path
String

要執行的 URL 路徑。The URL path to execute.

Exceptions

目前的 HttpContextnullThe current HttpContext is null.

-或--or- 執行 path 指定的處理常式時發生錯誤。An error occurred while executing the handler specified by path.

pathnullpath is null.

-或--or- path 不是虛擬路徑。path is not a virtual path.

Examples

下列範例會在目前的目錄中顯示 .aspx 頁面 "Updateinfo"。The following example displays the .aspx page "Updateinfo.aspx" in the current directory. 程式執行會在 [Updateinfo] 頁面顯示之後回到起始頁。Program execution returns to the starting page after the Updateinfo.aspx page is displayed.

Server.Execute("updateinfo.aspx");

Server.Execute("updateinfo.aspx")
   

Remarks

在完成新頁面的執行之後,Execute 方法會繼續執行原始頁面。The Execute method continues execution of the original page after execution of the new page is completed. Transfer 方法會無條件地將執行傳輸至另一個處理常式。The Transfer method unconditionally transfers execution to another handler.

ASP.NET 不會驗證目前的使用者是否有權查看 Execute 方法所傳遞的資源。ASP.NET does not verify that the current user is authorized to view the resource delivered by the Execute method. 雖然 ASP.NET 授權和驗證邏輯會在呼叫原始資源處理常式之前執行,但 ASP.NET 會直接呼叫 Execute 方法所指出的處理常式,而不會重新執行新資源的驗證和授權邏輯。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 Execute 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 方法來強制執行重新授權,而不是 Execute 方法。You can force reauthorization by using the Redirect method instead of the Execute method. Redirect 會執行用戶端重新導向,瀏覽器會在其中要求新的資源。Redirect 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.

您可以在應用程式呼叫 Execute 方法之前,藉由整合使用 IsInRole 方法的自訂授權方法,確認使用者有權查看資源。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 Execute method.

Execute(String, Boolean)

在目前要求的內容中,執行指定虛擬路徑的處理常式,並指定是否清除 QueryStringForm 集合。Executes the handler for the specified virtual path in the context of the current request and specifies whether to clear the QueryString and Form collections.

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

Parameters

path
String

要執行的 URL 路徑。The URL path to execute.

preserveForm
Boolean

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

Exceptions

目前的 HttpContextnullThe current HttpContext is null.

-或--or- 執行 path 指定的處理常式時發生錯誤。An error occurred while executing the handler specified by path.

pathnullpath is null.

-或--or- path 不是虛擬路徑。path is not a virtual path.

Examples

下列範例示範如何在目前要求中執行 .aspx 頁面 Updateinfo.aspx,並保留 QueryStringForm 集合。The following example shows how to execute the .aspx page Updateinfo.aspx in the current request and preserve the QueryString and Form collections. 在顯示 Updateinfo.aspx 之後,程式執行會回到起始頁。Program execution returns to the starting page after Updateinfo.aspx is displayed.

private void Page_Load(Object sender, EventArgs e)
{
    Server.Execute("updateinfo.aspx", true);
} 
Sub Page_Load(ByVal Sender As Object, ByVal e As EventArgs)
    Server.Execute("updateinfo.aspx", True)
End Sub

See also

Execute(String, TextWriter)

在目前要求的內容中,執行指定虛擬路徑的處理常式。Executes the handler for the specified virtual path in the context of the current request. TextWriter 會擷取已執行處理常式的輸出。A TextWriter captures output from the executed handler.

public:
 void Execute(System::String ^ path, System::IO::TextWriter ^ writer);
public void Execute (string path, System.IO.TextWriter writer);
member this.Execute : string * System.IO.TextWriter -> unit
Public Sub Execute (path As String, writer As TextWriter)

Parameters

path
String

要執行的 URL 路徑。The URL path to execute.

writer
TextWriter

要擷取輸出的 TextWriterThe TextWriter to capture the output.

Exceptions

目前的 HttpContextnullThe current HttpContext is null.

-或--or- 執行 path 指定的處理常式時發生錯誤。An error occurred while executing the handler specified by path.

pathnullpath is null.

-或--or- path 不是虛擬路徑。path is not a virtual path.

Examples

下列範例會在目前目錄中的伺服器上執行 Login.aspx 頁面,並透過 StringWriter 物件 writer接收頁面的輸出。The following example executes the Login.aspx page on the server in the current directory and receives the output from the page through the StringWriter object writer. 它會將從 writer 收到的 HTML 資料流程寫入 HTTP 輸出資料流程。It writes the HTML stream received from writer to the HTTP output stream.

StringWriter writer = new StringWriter();
Server.Execute("Login.aspx", writer);
Response.Write("<H3>Please Login:</H3><br>"+ writer.ToString());

Dim writer As New StringWriter
Server.Execute("Login.aspx", writer)
Response.Write("<H3>Please Login:</H3><br>" & writer.ToString())
   

Remarks

當指定的虛擬路徑完成執行之後,Execute 方法會繼續執行原始要求。The Execute method continues execution of the original request after execution of the virtual path specified is completed. Transfer 方法會無條件地將執行傳輸至另一個處理常式。The Transfer method unconditionally transfers execution to another handler.

ASP.NET 不會驗證目前的使用者是否有權查看 Execute 方法所傳遞的資源。ASP.NET does not verify that the current user is authorized to view the resource delivered by the Execute method. 雖然 ASP.NET 授權和驗證邏輯會在呼叫原始資源處理常式之前執行,但 ASP.NET 會直接呼叫 Execute 方法所指出的處理常式,而不會重新執行新資源的驗證和授權邏輯。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 Execute 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 方法來強制執行重新授權,而不是 Execute 方法。You can force reauthorization by using the Redirect method instead of the Execute method. Redirect 會執行用戶端重新導向,瀏覽器會在其中要求新的資源。Redirect 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.

您可以在應用程式呼叫 Execute 方法之前,藉由整合使用 IsInRole 方法的自訂授權方法,確認使用者有權查看資源。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 Execute method.

See also

Execute(String, TextWriter, Boolean)

在目前要求的內容中,執行指定虛擬路徑的處理常式。Executes the handler for the specified virtual path in the context of the current request. TextWriter 會擷取網頁的輸出,並且布林參數會指定是否要清除 QueryStringForm 集合。A TextWriter captures output from the page and a Boolean parameter specifies whether to clear the QueryString and Form collections.

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

Parameters

path
String

要執行的 URL 路徑。The URL path to execute.

writer
TextWriter

要擷取輸出的 TextWriterThe TextWriter to capture the output.

preserveForm
Boolean

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

Exceptions

目前 HttpContext 是 Null 參考 (在 Visual Basic 中為 Nothing)。The current HttpContext is a null reference (Nothing in Visual Basic).

-或--or- path 結束於句點 (.)。path ends with a period (.).

-或--or- 執行 path 指定的處理常式時發生錯誤。An error occurred while executing the handler specified by path.

pathnullpath is null.

path 不是虛擬路徑。path is not a virtual path.

Examples

下列範例會在目前目錄中的伺服器上執行 Login.aspx 頁面,並透過 StringWriter 物件 writer接收頁面的輸出。The following example executes the Login.aspx page on the server in the current directory and receives the output from the page through the StringWriter object writer. 它會將從 writer 收到的 HTML 資料流程寫入 HTTP 輸出資料流程。It writes the HTML stream received from writer to the HTTP output stream. FormQueryString 集合的內容會保留下來。The contents of the Form and QueryString collections are preserved.

private void Page_Load(Object sender, EventArgs e)
{
    System.IO.StringWriter writer = new System.IO.StringWriter();
    Server.Execute("Login.aspx", writer, true);
    Response.Write("<h3>Please Login:</h3><br />" + writer.ToString());
} 
Sub Page_Load(ByVal Sender As Object, ByVal e As EventArgs)
    Dim writer As System.IO.StringWriter = New System.IO.StringWriter()
    Server.Execute("Login.aspx", writer, True)
    Response.Write("<h3>Please Login:</h3><br />" + writer.ToString())
End Sub

Remarks

在執行指定的虛擬路徑完成後,Execute 方法會繼續執行原始要求。The Execute method continues execution of the original request after execution of the specified virtual path is completed. Transfer 方法會無條件地將執行傳輸至另一個處理常式。The Transfer method unconditionally transfers execution to another handler.

ASP.NET 不會驗證目前的使用者是否有權查看 Execute 方法所傳遞的資源。ASP.NET does not verify that the current user is authorized to view the resource delivered by the Execute method. 雖然 ASP.NET 授權和驗證邏輯會在呼叫原始資源處理常式之前執行,但 ASP.NET 會直接呼叫 Execute 方法所指出的處理常式,而不會重新執行新資源的驗證和授權邏輯。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 Execute 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 方法來強制執行重新授權,而不是 Execute 方法。You can force reauthorization by using the Redirect method instead of the Execute method. Redirect 會執行用戶端重新導向,瀏覽器會在其中要求新的資源。Redirect 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.

您可以在應用程式呼叫 Execute 方法之前,藉由整合使用 IsInRole 方法的自訂授權方法,確認使用者有權查看資源。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 Execute method.

See also

Execute(IHttpHandler, TextWriter, Boolean)

在目前要求的內容中,執行指定虛擬路徑的處理常式。Executes the handler for the specified virtual path in the context of the current request. TextWriter 會擷取已執行處理常式的輸出,並且布林參數會指定是否要清除 QueryStringForm 集合。A TextWriter captures output from the executed handler and a Boolean parameter specifies whether to clear the QueryString and Form collections.

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

Parameters

handler
IHttpHandler

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

writer
TextWriter

要擷取輸出的 TextWriterThe TextWriter to capture the output.

preserveForm
Boolean

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

Exceptions

執行 handler 指定的處理常式時發生錯誤。An error occurred while executing the handler specified by handler.

handler 參數是 nullThe handler parameter is null.

Remarks

您可以撰寫自訂的 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 處理常式可讓您與執行 Internet Information Services (IIS)之 Web 服務器的低層級要求和回應服務互動,並提供與 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.

ASP.NET 不會驗證目前的使用者是否已獲授權,可以查看由 Execute 方法所傳遞的資源。ASP.NET does not verify that the current user is authorized to view the resource that is delivered by the Execute method. 雖然 ASP.NET 授權和驗證邏輯會在呼叫原始資源處理常式之前執行,但 ASP.NET 會直接呼叫 Execute 方法所指出的處理常式,而不會重新執行新資源的驗證和授權邏輯。Although the ASP.NET authorization and authentication logic runs before the original resource handler is called, ASP.NET directly calls the handler that is indicated by the Execute 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 gain access to the resource, the application should force reauthorization or provide a custom access-control mechanism.

您可以使用 Redirect 方法來強制執行重新授權,而不是 Execute 方法。You can force reauthorization by using the Redirect method instead of the Execute method. Redirect 會執行用戶端重新導向,瀏覽器會在其中要求新的資源。The Redirect 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.

您可以在應用程式呼叫 Execute 方法之前,藉由整合使用 IsInRole 方法的自訂授權方法,確認使用者有權查看資源。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 Execute method.

See also

Applies to