New tests.
[mono.git] / mcs / class / System.Web.Mvc2 / System.Web.Mvc / RedirectResult.cs
1 /* ****************************************************************************\r
2  *\r
3  * Copyright (c) Microsoft Corporation. All rights reserved.\r
4  *\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
8  *\r
9  * You must not remove this notice, or any other, from this software.\r
10  *\r
11  * ***************************************************************************/\r
12 \r
13 namespace System.Web.Mvc {\r
14     using System;\r
15     using System.Diagnostics.CodeAnalysis;\r
16     using System.Web.Mvc.Resources;\r
17 \r
18     // represents a result that performs a redirection given some URI\r
19     public class RedirectResult : ActionResult {\r
20 \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
26             }\r
27 \r
28             Url = url;\r
29         }\r
30 \r
31         [SuppressMessage("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings",\r
32             Justification = "Response.Redirect() takes its URI as a string parameter.")]\r
33         public string Url {\r
34             get;\r
35             private set;\r
36         }\r
37 \r
38         public override void ExecuteResult(ControllerContext context) {\r
39             if (context == null) {\r
40                 throw new ArgumentNullException("context");\r
41             }\r
42             if (context.IsChildAction) {\r
43                 throw new InvalidOperationException(MvcResources.RedirectAction_CannotRedirectInChildAction);\r
44             }\r
45 \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
49         }\r
50 \r
51     }\r
52 }\r