HttpResponse.RedirectToRoute 方法

定義

使用路由參數值、路由名稱或兩者都使用,將要求重新導向至新的 URL。

多載

RedirectToRoute(Object)

使用路由參數值,將要求重新導向至新的 URL。

RedirectToRoute(String)

使用路由名稱,將要求重新導向至新的 URL。

RedirectToRoute(RouteValueDictionary)

使用路由參數值,將要求重新導向至新的 URL。

RedirectToRoute(String, Object)

使用路由參數值及路由名稱,將要求重新導向至新的 URL。

RedirectToRoute(String, RouteValueDictionary)

使用路由參數值及路由名稱,將要求重新導向至新的 URL。

RedirectToRoute(Object)

使用路由參數值,將要求重新導向至新的 URL。

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

參數

routeValues
Object

路由參數值。

例外狀況

沒有路由對應到指定的路由參數。

在 HTTP 標頭送出之後嘗試重新導向。

範例

下列範例示範如何呼叫這個方法,以重新導向至具有具名 productidcategory參數的路由。

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

備註

提供這個方法以方便撰寫程序代碼。 這相當於呼叫 方法, Redirect(String, Boolean) 並將第二個參數設定為 false

這個方法會使用 RouteValueDictionary.RouteValueDictionary(Object) 建構函式,將傳入routeValues物件的物件System.Web.Routing.RouteValueDictionary轉換成 物件。 RouteCollection.GetVirtualPath接著會呼叫 方法來判斷 URL。

ASP.NET 傳回 302 HTTP 狀態代碼來執行重新導向。

另請參閱

適用於

RedirectToRoute(String)

使用路由名稱,將要求重新導向至新的 URL。

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

參數

routeName
String

路由的名稱。

例外狀況

沒有路由對應到指定的路由參數。

在 HTTP 標頭送出之後嘗試重新導向。

範例

下列範例示範如何呼叫這個方法,以重新導向至名為 Products的路由。

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

備註

提供這個方法以方便撰寫程序代碼。 這相當於呼叫 方法, Redirect(String, Boolean) 並將第二個參數設定為 false

這個方法會使用 RouteCollection.GetVirtualPath 方法,將傳入 routeName URL 的路由名稱轉換為 URL。

ASP.NET 傳回 302 HTTP 狀態代碼來執行重新導向。

另請參閱

適用於

RedirectToRoute(RouteValueDictionary)

使用路由參數值,將要求重新導向至新的 URL。

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

路由參數值。

例外狀況

沒有路由對應到指定的路由參數。

在 HTTP 標頭送出之後嘗試重新導向。

範例

下列範例示範如何呼叫這個方法,以重新導向至具有具名 productidcategory參數的路由。

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

備註

提供這個方法以方便撰寫程序代碼。 這相當於呼叫 方法, Redirect(String, Boolean) 並將第二個參數設定為 false

這個方法會 RouteCollection.GetVirtualPath 呼叫 方法來判斷 URL。

ASP.NET 傳回 302 HTTP 狀態代碼來執行重新導向。

另請參閱

適用於

RedirectToRoute(String, Object)

使用路由參數值及路由名稱,將要求重新導向至新的 URL。

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

路由的名稱。

routeValues
Object

路由參數值。

例外狀況

沒有路由對應到指定的路由參數。

在 HTTP 標頭送出之後嘗試重新導向。

範例

下列範例示範如何呼叫這個方法,以重新導向至名為 Product 的路由,以及具有名為 productidcategory的參數。

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

備註

提供這個方法以方便撰寫程序代碼。 這相當於呼叫 方法, Redirect(String, Boolean) 並將第二個參數設定為 false

這個方法會使用 RouteValueDictionary.RouteValueDictionary(Object) 建構函式,將傳入routeValues物件的物件System.Web.Routing.RouteValueDictionary轉換成 物件。 RouteCollection.GetVirtualPath接著會呼叫 方法來判斷 URL。

ASP.NET 傳回 302 HTTP 狀態代碼來執行重新導向。

另請參閱

適用於

RedirectToRoute(String, RouteValueDictionary)

使用路由參數值及路由名稱,將要求重新導向至新的 URL。

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

路由的名稱。

routeValues
RouteValueDictionary

路由參數值。

例外狀況

沒有路由對應到指定的路由參數。

在 HTTP 標頭送出之後嘗試重新導向。

範例

下列範例示範如何呼叫這個方法,以重新導向至名為 Product 的路由,以及具有名為 productidcategory的參數。

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

備註

提供這個方法以方便撰寫程序代碼。 這相當於呼叫 方法, Redirect(String, Boolean) 並將第二個參數設定為 false

系統會 RouteCollection.GetVirtualPath 呼叫 方法來判斷 URL。

ASP.NET 傳回 302 HTTP 狀態代碼來執行重新導向。

另請參閱

適用於