HttpServerUtility.Execute HttpServerUtility.Execute HttpServerUtility.Execute HttpServerUtility.Execute Method

定義

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

多載

Execute(String) Execute(String) Execute(String) Execute(String)

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

Execute(String, Boolean) Execute(String, Boolean) Execute(String, Boolean) 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) Execute(String, TextWriter) Execute(String, TextWriter) 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) Execute(String, TextWriter, Boolean) Execute(String, TextWriter, Boolean) 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) Execute(IHttpHandler, TextWriter, Boolean) Execute(IHttpHandler, TextWriter, Boolean) 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) Execute(String) Execute(String) 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)

參數

path
String String String String

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

例外狀況

目前的 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.

範例

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

Server.Execute("updateinfo.aspx");
   
Server.Execute("updateinfo.aspx")
   

備註

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.

您可以確認使用者已透過合併自訂授權使用的方法,檢視資源的權限IsInRole方法,應用程式會呼叫再Execute方法。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) Execute(String, Boolean) Execute(String, Boolean) 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)

參數

path
String String String String

要執行的 URL 路徑。The URL path 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.

例外狀況

目前的 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.

範例

下列範例示範如何執行.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
另請參閱

Execute(String, TextWriter) Execute(String, TextWriter) Execute(String, TextWriter) 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)

參數

path
String String String String

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

writer
TextWriter TextWriter TextWriter TextWriter

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

例外狀況

目前的 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.

範例

下列範例會執行Login.aspx頁面上目前的目錄中的伺服器,並從網頁透過接收輸出StringWriter物件writerThe 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. 它會將寫入從收到的 HTML 資料流writer至 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())
   

備註

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.

您可以確認使用者已透過合併自訂授權使用的方法,檢視資源的權限IsInRole方法,應用程式會呼叫再Execute方法。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, TextWriter, Boolean) Execute(String, TextWriter, Boolean) Execute(String, TextWriter, Boolean) 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)

參數

path
String String String String

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

writer
TextWriter TextWriter TextWriter TextWriter

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

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.

例外狀況

目前 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.

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

範例

下列範例會執行Login.aspx頁面上目前的目錄中的伺服器,並從網頁透過接收輸出StringWriter物件writerThe 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. 它會將寫入從收到的 HTML 資料流writer至 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

備註

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.

您可以確認使用者已透過合併自訂授權使用的方法,檢視資源的權限IsInRole方法,應用程式會呼叫再Execute方法。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(IHttpHandler, TextWriter, Boolean) Execute(IHttpHandler, TextWriter, Boolean) Execute(IHttpHandler, TextWriter, Boolean) 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)

參數

handler
IHttpHandler IHttpHandler IHttpHandler IHttpHandler

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

writer
TextWriter TextWriter TextWriter TextWriter

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

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.

例外狀況

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

handler 參數為 nullThe handler parameter is null.

備註

您可以撰寫自訂的 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.

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.

您可以確認使用者已透過合併自訂授權使用的方法,檢視資源的權限IsInRole方法,應用程式會呼叫再Execute方法。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.

另請參閱

適用於