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 RouteValueDictionary.RouteValueDictionary(Object)此函式,將傳入的System.Web.Routing.RouteValueDictionary物件轉換成物件。This method converts the object that is passed in routeValues to a System.Web.Routing.RouteValueDictionary object by using the RouteValueDictionary.RouteValueDictionary(Object) constructor. 接著會呼叫方法來判斷 URL。 RouteCollection.GetVirtualPathThe 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 RouteValueDictionary.RouteValueDictionary(Object)此函式,將傳入的System.Web.Routing.RouteValueDictionary物件轉換成物件。This method converts the object that is passed in routeValues to a System.Web.Routing.RouteValueDictionary object by using the RouteValueDictionary.RouteValueDictionary(Object) constructor. 接著會呼叫方法來判斷 URL。 RouteCollection.GetVirtualPathThe 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.

另請參閱

適用於