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方法保留Form和集合。 QueryStringThe 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

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

如果将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.

适用于