1 /* ****************************************************************************
\r
3 * Copyright (c) Microsoft Corporation. All rights reserved.
\r
5 * This software is subject to the Microsoft Public License (Ms-PL).
\r
6 * A copy of the license can be found in the license.htm file included
\r
7 * in this distribution.
\r
9 * You must not remove this notice, or any other, from this software.
\r
11 * ***************************************************************************/
\r
13 namespace System.Web.Mvc {
\r
15 using System.Diagnostics.CodeAnalysis;
\r
16 using System.Web.Mvc.Resources;
\r
18 // represents a result that performs a redirection given some URI
\r
19 public class RedirectResult : ActionResult {
\r
21 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "0#",
\r
22 Justification = "Response.Redirect() takes its URI as a string parameter.")]
\r
23 public RedirectResult(string url) {
\r
24 if (String.IsNullOrEmpty(url)) {
\r
25 throw new ArgumentException(MvcResources.Common_NullOrEmpty, "url");
\r
31 [SuppressMessage("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings",
\r
32 Justification = "Response.Redirect() takes its URI as a string parameter.")]
\r
38 public override void ExecuteResult(ControllerContext context) {
\r
39 if (context == null) {
\r
40 throw new ArgumentNullException("context");
\r
42 if (context.IsChildAction) {
\r
43 throw new InvalidOperationException(MvcResources.RedirectAction_CannotRedirectInChildAction);
\r
46 string destinationUrl = UrlHelper.GenerateContentUrl(Url, context.HttpContext);
\r
47 context.Controller.TempData.Keep();
\r
48 context.HttpContext.Response.Redirect(destinationUrl, false /* endResponse */);
\r