HttpResponse.RedirectToRoute 方法

定义

使用路由参数值和/或路由名称将请求重定向到新 URL。Redirects a request to a new URL by using route parameter values, a route name, or both.

重载

RedirectToRoute(Object)

使用路由参数值将请求重定向到新 URL。Redirects a request to a new URL by using route parameter values.

RedirectToRoute(String)

使用路由名称将请求重定向到新 URL。Redirects a request to a new URL by using a route name.

RedirectToRoute(RouteValueDictionary)

使用路由参数值将请求重定向到新 URL。Redirects a request to a new URL by using route parameter values.

RedirectToRoute(String, Object)

使用路由参数值和路由名称将请求重定向到新 URL。Redirects a request to a new URL by using route parameter values and a route name.

RedirectToRoute(String, RouteValueDictionary)

使用路由参数值和路由名称将请求重定向到新 URL。Redirects a request to a new URL by using route parameter values and a route name.

RedirectToRoute(Object)

使用路由参数值将请求重定向到新 URL。Redirects a request to a new URL by using route parameter values.

public:
 void RedirectToRoute(System::Object ^ routeValues);
public void RedirectToRoute (object routeValues);
member this.RedirectToRoute : obj -> unit
Public Sub RedirectToRoute (routeValues As Object)

参数

routeValues
Object

路由参数值。The route parameter values.

异常

没有与指定路由参数对应的路由。No route corresponds to the specified route parameters.

在发送 HTTP 标头之后尝试进行重定向。Redirection was attempted after the HTTP headers had been sent.

示例

下面的示例演示如何调用此方法以重定向到具有名为productidcategory的参数的路由。The following example shows how to call this method to redirect to a route that has parameters that are named productid and category.

Response.RedirectToRoute(  
  New With {.productid = "1", .category = "widgets"})  
Response.RedirectToRoute(  
  new { productid = "1", category = "widgets" });  

注解

提供此方法是为了便于编码。This method is provided for coding convenience. 它等效于调用Redirect(String, Boolean)方法,并将第二个参数设置为。 falseIt is equivalent to calling the Redirect(String, Boolean) method with the second parameter set to false.

此方法使用routeValues System.Web.Routing.RouteValueDictionary 构造函数将传入的对象RouteValueDictionary.RouteValueDictionary(Object)转换为对象。This method converts the object that is passed in routeValues to a System.Web.Routing.RouteValueDictionary object by using the RouteValueDictionary.RouteValueDictionary(Object) constructor. 然后RouteCollection.GetVirtualPath调用方法来确定 URL。The RouteCollection.GetVirtualPath method is then called to determine the URL.

ASP.NET 通过返回 302 HTTP 状态代码来执行重定向。ASP.NET performs the redirection by returning a 302 HTTP status code.

另请参阅

RedirectToRoute(String)

使用路由名称将请求重定向到新 URL。Redirects a request to a new URL by using a route name.

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

参数

routeName
String

路由的名称。The name of the route.

异常

没有与指定路由参数对应的路由。No route corresponds to the specified route parameters.

在发送 HTTP 标头之后尝试进行重定向。Redirection was attempted after the HTTP headers had been sent.

示例

下面的示例演示如何调用此方法以重定向到名Products为的路由。The following example shows how to call this method to redirect to a route that is named Products.

Response.RedirectToRoute("Products")  
Response.RedirectToRoute("Products");  

注解

提供此方法是为了便于编码。This method is provided for coding convenience. 它等效于调用Redirect(String, Boolean)方法,并将第二个参数设置为。 falseIt is equivalent to calling the Redirect(String, Boolean) method with the second parameter set to false.

此方法routeName RouteCollection.GetVirtualPath使用方法将传入的路由名称转换为 URL。This method converts the route name that is passed in routeName to a URL by using the RouteCollection.GetVirtualPath method.

ASP.NET 通过返回 302 HTTP 状态代码来执行重定向。ASP.NET performs the redirection by returning a 302 HTTP status code.

另请参阅

RedirectToRoute(RouteValueDictionary)

使用路由参数值将请求重定向到新 URL。Redirects a request to a new URL by using route parameter values.

public:
 void RedirectToRoute(System::Web::Routing::RouteValueDictionary ^ routeValues);
public void RedirectToRoute (System.Web.Routing.RouteValueDictionary routeValues);
member this.RedirectToRoute : System.Web.Routing.RouteValueDictionary -> unit
Public Sub RedirectToRoute (routeValues As RouteValueDictionary)

参数

routeValues
RouteValueDictionary

路由参数值。The route parameter values.

异常

没有与指定路由参数对应的路由。No route corresponds to the specified route parameters.

在发送 HTTP 标头之后尝试进行重定向。Redirection was attempted after the HTTP headers had been sent.

示例

下面的示例演示如何调用此方法以重定向到具有名为productidcategory的参数的路由。The following example shows how to call this method to redirect to a route that has parameters that are named productid and category.

Response.RedirectToRoute(  
  new RouteValueDictionary {productId="1", category="widgets"})  
Response.RedirectToRoute(  
  (new RouteValueDictionary {productId="1", category="widgets"});  

注解

提供此方法是为了便于编码。This method is provided for coding convenience. 它等效于调用Redirect(String, Boolean)方法,并将第二个参数设置为。 falseIt is equivalent to calling the Redirect(String, Boolean) method with the second parameter set to false.

此方法调用RouteCollection.GetVirtualPath方法来确定 URL。This method calls the RouteCollection.GetVirtualPath method to determine the URL.

ASP.NET 通过返回 302 HTTP 状态代码来执行重定向。ASP.NET performs the redirection by returning a 302 HTTP status code.

另请参阅

RedirectToRoute(String, Object)

使用路由参数值和路由名称将请求重定向到新 URL。Redirects a request to a new URL by using route parameter values and a route name.

public:
 void RedirectToRoute(System::String ^ routeName, System::Object ^ routeValues);
public void RedirectToRoute (string routeName, object routeValues);
member this.RedirectToRoute : string * obj -> unit
Public Sub RedirectToRoute (routeName As String, routeValues As Object)

参数

routeName
String

路由的名称。The name of the route.

routeValues
Object

路由参数值。The route parameter values.

异常

没有与指定路由参数对应的路由。No route corresponds to the specified route parameters.

在发送 HTTP 标头之后尝试进行重定向。Redirection was attempted after the HTTP headers had been sent.

示例

下面的示例演示如何调用此方法以重定向到名Product为且具有名为productidcategory的参数的路由。The following example shows how to call this method to redirect to a route that is named Product and that has parameters that are named productid and category.

Response.RedirectToRoute("Product",  
  New With {.productid = "1", .category = "widgets"})  
Response.RedirectToRoute("Product",  
  new { productid = "1", category = "widgets" });  

注解

提供此方法是为了便于编码。This method is provided for coding convenience. 它等效于调用Redirect(String, Boolean)方法,并将第二个参数设置为。 falseIt is equivalent to calling the Redirect(String, Boolean) method with the second parameter set to false.

此方法使用routeValues System.Web.Routing.RouteValueDictionary 构造函数将传入的对象RouteValueDictionary.RouteValueDictionary(Object)转换为对象。This method converts the object that is passed in routeValues to a System.Web.Routing.RouteValueDictionary object by using the RouteValueDictionary.RouteValueDictionary(Object) constructor. 然后RouteCollection.GetVirtualPath调用方法来确定 URL。The RouteCollection.GetVirtualPath method is then called to determine the URL.

ASP.NET 通过返回 302 HTTP 状态代码来执行重定向。ASP.NET performs the redirection by returning a 302 HTTP status code.

另请参阅

RedirectToRoute(String, RouteValueDictionary)

使用路由参数值和路由名称将请求重定向到新 URL。Redirects a request to a new URL by using route parameter values and a route name.

public:
 void RedirectToRoute(System::String ^ routeName, System::Web::Routing::RouteValueDictionary ^ routeValues);
public void RedirectToRoute (string routeName, System.Web.Routing.RouteValueDictionary routeValues);
member this.RedirectToRoute : string * System.Web.Routing.RouteValueDictionary -> unit
Public Sub RedirectToRoute (routeName As String, routeValues As RouteValueDictionary)

参数

routeName
String

路由的名称。The name of the route.

routeValues
RouteValueDictionary

路由参数值。The route parameter values.

异常

没有与指定路由参数对应的路由。No route corresponds to the specified route parameters.

在发送 HTTP 标头之后尝试进行重定向。Redirection was attempted after the HTTP headers had been sent.

示例

下面的示例演示如何调用此方法以重定向到名Product为且具有名为productidcategory的参数的路由。The following example shows how to call this method to redirect to a route that is named Product and that has parameters that are named productid and category.

Response.RedirectToRoute("Product",  
  new RouteValueDictionary {productId="1", category="widgets"})  
Response.RedirectToRoute("Product",  
  (new RouteValueDictionary {productId="1", category="widgets"});  

注解

提供此方法是为了便于编码。This method is provided for coding convenience. 它等效于调用Redirect(String, Boolean)方法,并将第二个参数设置为。 falseIt is equivalent to calling the Redirect(String, Boolean) method with the second parameter set to false.

调用RouteCollection.GetVirtualPath方法来确定 URL。The RouteCollection.GetVirtualPath method is called to determine the URL.

ASP.NET 通过返回 302 HTTP 状态代码来执行重定向。ASP.NET performs the redirection by returning a 302 HTTP status code.

另请参阅

适用于