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"。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")
   

注解

完成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页面并QueryString保留和Form集合。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通过对象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())
   

注解

完成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通过对象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

注解

完成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

实现 IHttpHandler 以便向其传输当前请求的 HTTP 处理程序。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 处理程序来处理任何符合公共语言规范 (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.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.

可以通过在应用程序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.

另请参阅

适用于