2010-06-21 Marek Habersack <mhabersack@novell.com>
[mcs.git] / class / System.Web.Mvc / System.Web.Mvc / RedirectToRouteResult.cs
blobaa8f3d912f1b8b27abe5ad92697596b908f784f9
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 {
14 using System;
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 {
33 get;
34 private set;
37 public RouteValueDictionary RouteValues {
38 get;
39 private set;
42 internal RouteCollection Routes {
43 get {
44 if (_routes == null) {
45 _routes = RouteTable.Routes;
47 return _routes;
49 set {
50 _routes = value;
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 */);