HttpResponse.RedirectToRoute Method

Definition

Redirects a request to a new URL by using route parameter values, a route name, or both.

Overloads

RedirectToRoute(Object)

Redirects a request to a new URL by using route parameter values.

RedirectToRoute(String)

Redirects a request to a new URL by using a route name.

RedirectToRoute(RouteValueDictionary)

Redirects a request to a new URL by using route parameter values.

RedirectToRoute(String, Object)

Redirects a request to a new URL by using route parameter values and a route name.

RedirectToRoute(String, RouteValueDictionary)

Redirects a request to a new URL by using route parameter values and a route name.

RedirectToRoute(Object)

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)

Parameters

routeValues
Object

The route parameter values.

Exceptions

No route corresponds to the specified route parameters.

Redirection was attempted after the HTTP headers had been sent.

Examples

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" });

Remarks

This method is provided for coding convenience. It is equivalent to calling the Redirect(String, Boolean) method with the second parameter set to false.

This method converts the object that is passed in routeValues to a System.Web.Routing.RouteValueDictionary object by using the RouteValueDictionary.RouteValueDictionary(Object) constructor. The RouteCollection.GetVirtualPath method is then called to determine the URL.

ASP.NET performs the redirection by returning a 302 HTTP status code.

See also

Applies to

RedirectToRoute(String)

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)

Parameters

routeName
String

The name of the route.

Exceptions

No route corresponds to the specified route parameters.

Redirection was attempted after the HTTP headers had been sent.

Examples

The following example shows how to call this method to redirect to a route that is named Products.

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

Remarks

This method is provided for coding convenience. It is equivalent to calling the Redirect(String, Boolean) method with the second parameter set to false.

This method converts the route name that is passed in routeName to a URL by using the RouteCollection.GetVirtualPath method.

ASP.NET performs the redirection by returning a 302 HTTP status code.

See also

Applies to

RedirectToRoute(RouteValueDictionary)

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)

Parameters

routeValues
RouteValueDictionary

The route parameter values.

Exceptions

No route corresponds to the specified route parameters.

Redirection was attempted after the HTTP headers had been sent.

Examples

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"});

Remarks

This method is provided for coding convenience. It is equivalent to calling the Redirect(String, Boolean) method with the second parameter set to false.

This method calls the RouteCollection.GetVirtualPath method to determine the URL.

ASP.NET performs the redirection by returning a 302 HTTP status code.

See also

Applies to

RedirectToRoute(String, Object)

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)

Parameters

routeName
String

The name of the route.

routeValues
Object

The route parameter values.

Exceptions

No route corresponds to the specified route parameters.

Redirection was attempted after the HTTP headers had been sent.

Examples

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" });

Remarks

This method is provided for coding convenience. It is equivalent to calling the Redirect(String, Boolean) method with the second parameter set to false.

This method converts the object that is passed in routeValues to a System.Web.Routing.RouteValueDictionary object by using the RouteValueDictionary.RouteValueDictionary(Object) constructor. The RouteCollection.GetVirtualPath method is then called to determine the URL.

ASP.NET performs the redirection by returning a 302 HTTP status code.

See also

Applies to

RedirectToRoute(String, RouteValueDictionary)

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)

Parameters

routeName
String

The name of the route.

routeValues
RouteValueDictionary

The route parameter values.

Exceptions

No route corresponds to the specified route parameters.

Redirection was attempted after the HTTP headers had been sent.

Examples

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"});

Remarks

This method is provided for coding convenience. It is equivalent to calling the Redirect(String, Boolean) method with the second parameter set to false.

The RouteCollection.GetVirtualPath method is called to determine the URL.

ASP.NET performs the redirection by returning a 302 HTTP status code.

See also

Applies to