1
/* ****************************************************************************
3 * Copyright (c) Microsoft Corporation. All rights reserved.
5 * This software is subject to the Microsoft Public License (Ms-PL).
6 * A copy of the license can be found in the license.htm file included
7 * in this distribution.
9 * You must not remove this notice, or any other, from this software.
11 * ***************************************************************************/
13 namespace System
.Web
.Mvc
{
15 using System
.Web
.Mvc
.Resources
;
16 using System
.Web
.Routing
;
18 // represents a result that performs a redirection given some values dictionary
19 public class RedirectToRouteResult
: ActionResult
{
21 private RouteCollection _routes
;
23 public RedirectToRouteResult(RouteValueDictionary routeValues
) :
24 this(null, routeValues
) {
27 public RedirectToRouteResult(string routeName
, RouteValueDictionary routeValues
) {
28 RouteName
= routeName
?? String
.Empty
;
29 RouteValues
= routeValues
?? new RouteValueDictionary();
32 public string RouteName
{
37 public RouteValueDictionary RouteValues
{
42 internal RouteCollection Routes
{
44 if (_routes
== null) {
45 _routes
= RouteTable
.Routes
;
54 public override void ExecuteResult(ControllerContext context
) {
55 if (context
== null) {
56 throw new ArgumentNullException("context");
59 string destinationUrl
= UrlHelper
.GenerateUrl(RouteName
, null /* actionName */, null /* controllerName */, RouteValues
, Routes
, context
.RequestContext
, false /* includeImplicitMvcValues */);
60 if (String
.IsNullOrEmpty(destinationUrl
)) {
61 throw new InvalidOperationException(MvcResources
.ActionRedirectResult_NoRouteMatched
);
64 context
.HttpContext
.Response
.Redirect(destinationUrl
, false /* endResponse */);