1 namespace System.Web.Mvc {
3 using System.Diagnostics.CodeAnalysis;
4 using System.Web.Mvc.Resources;
6 // represents a result that performs a redirection given some URI
7 public class RedirectResult : ActionResult {
9 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "0#", Justification = "Response.Redirect() takes its URI as a string parameter.")]
10 public RedirectResult(string url)
11 : this(url, permanent: false) {
14 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "0#", Justification = "Response.Redirect() takes its URI as a string parameter.")]
15 public RedirectResult(string url, bool permanent) {
16 if (String.IsNullOrEmpty(url)) {
17 throw new ArgumentException(MvcResources.Common_NullOrEmpty, "url");
20 Permanent = permanent;
24 public bool Permanent {
29 [SuppressMessage("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings", Justification = "Response.Redirect() takes its URI as a string parameter.")]
35 public override void ExecuteResult(ControllerContext context) {
36 if (context == null) {
37 throw new ArgumentNullException("context");
39 if (context.IsChildAction) {
40 throw new InvalidOperationException(MvcResources.RedirectAction_CannotRedirectInChildAction);
43 string destinationUrl = UrlHelper.GenerateContentUrl(Url, context.HttpContext);
44 context.Controller.TempData.Keep();
47 context.HttpContext.Response.RedirectPermanent(destinationUrl, endResponse: false);
50 context.HttpContext.Response.Redirect(destinationUrl, endResponse: false);