From 327ccf75352a7288ee0fbd126bf858053b0df98a Mon Sep 17 00:00:00 2001 From: hammett Date: Sat, 1 Mar 2008 18:17:26 +0000 Subject: [PATCH] Added RedirectUsingNamedRoute git-svn-id: https://svn.castleproject.org/svn/castle/trunk@4863 73e77b4c-caa6-f847-a29a-24ab75ae54b6 --- MonoRail/Castle.MonoRail.Framework/Controller.cs | 32 +++++++++++++++++ .../Castle.MonoRail.Framework/IRedirectSupport.cs | 24 +++++++++++++ .../Internal/BaseResponse.cs | 42 +++++++++++++++++++++- .../Services/IUrlBuilder.cs | 10 +++++- 4 files changed, 106 insertions(+), 2 deletions(-) diff --git a/MonoRail/Castle.MonoRail.Framework/Controller.cs b/MonoRail/Castle.MonoRail.Framework/Controller.cs index e7a866680..da73c1193 100644 --- a/MonoRail/Castle.MonoRail.Framework/Controller.cs +++ b/MonoRail/Castle.MonoRail.Framework/Controller.cs @@ -992,6 +992,38 @@ namespace Castle.MonoRail.Framework } /// + /// Redirects using a named route. + /// The name must exists otherwise a will be thrown. + /// + /// Route name. + public void RedirectUsingNamedRoute(string routeName) + { + Response.RedirectUsingNamedRoute(routeName); + } + + /// + /// Redirects using a named route. + /// The name must exists otherwise a will be thrown. + /// + /// Route name. + /// The route parameters. + public void RedirectUsingNamedRoute(string routeName, object routeParameters) + { + Response.RedirectUsingNamedRoute(routeName, routeParameters); + } + + /// + /// Redirects using a named route. + /// The name must exists otherwise a will be thrown. + /// + /// Route name. + /// The route parameters. + public void RedirectUsingNamedRoute(string routeName, IDictionary routeParameters) + { + Response.RedirectUsingNamedRoute(routeName, routeParameters); + } + + /// /// Tries to resolve the target redirect url by using the routing rules registered. /// /// The desired action on the target controller. diff --git a/MonoRail/Castle.MonoRail.Framework/IRedirectSupport.cs b/MonoRail/Castle.MonoRail.Framework/IRedirectSupport.cs index 06c3e7e4e..7dbc03c55 100644 --- a/MonoRail/Castle.MonoRail.Framework/IRedirectSupport.cs +++ b/MonoRail/Castle.MonoRail.Framework/IRedirectSupport.cs @@ -129,6 +129,30 @@ namespace Castle.MonoRail.Framework /// The querystring entries as an anonymous dictionary void Redirect(string area, string controller, string action, object queryStringAnonymousDictionary); + + /// + /// Redirects using a named route. + /// The name must exists otherwise a will be thrown. + /// + /// Route name. + void RedirectUsingNamedRoute(string routeName); + + /// + /// Redirects using a named route. + /// The name must exists otherwise a will be thrown. + /// + /// Route name. + /// The route parameters. + void RedirectUsingNamedRoute(string routeName, object routeParameters); + + /// + /// Redirects using a named route. + /// The name must exists otherwise a will be thrown. + /// + /// Route name. + /// The route parameters. + void RedirectUsingNamedRoute(string routeName, IDictionary routeParameters); + /// /// Tries to resolve the target redirect url by using the routing rules registered. diff --git a/MonoRail/Castle.MonoRail.Framework/Internal/BaseResponse.cs b/MonoRail/Castle.MonoRail.Framework/Internal/BaseResponse.cs index 327bd4d89..9d0748d27 100644 --- a/MonoRail/Castle.MonoRail.Framework/Internal/BaseResponse.cs +++ b/MonoRail/Castle.MonoRail.Framework/Internal/BaseResponse.cs @@ -58,7 +58,7 @@ namespace Castle.MonoRail.Framework.Internal this.referrer = referrer; } - #region abstracts + #region abstracts /// /// Gets or sets the status code. @@ -374,6 +374,46 @@ namespace Castle.MonoRail.Framework.Internal } /// + /// Redirects using a named route. + /// The name must exists otherwise a will be thrown. + /// + /// Route name. + public void RedirectUsingNamedRoute(string routeName) + { + UrlBuilderParameters @params = new UrlBuilderParameters(); + @params.RouteName = routeName; + RedirectToUrl(urlBuilder.BuildUrl(currentUrl, @params), false); + } + + /// + /// Redirects using a named route. + /// The name must exists otherwise a will be thrown. + /// + /// Route name. + /// The route parameters. + public void RedirectUsingNamedRoute(string routeName, object routeParameters) + { + UrlBuilderParameters @params = new UrlBuilderParameters(); + @params.RouteName = routeName; + @params.RouteParameters = routeParameters; + RedirectToUrl(urlBuilder.BuildUrl(currentUrl, @params), false); + } + + /// + /// Redirects using a named route. + /// The name must exists otherwise a will be thrown. + /// + /// Route name. + /// The route parameters. + public void RedirectUsingNamedRoute(string routeName, IDictionary routeParameters) + { + UrlBuilderParameters @params = new UrlBuilderParameters(); + @params.RouteName = routeName; + @params.RouteParameters = routeParameters; + RedirectToUrl(urlBuilder.BuildUrl(currentUrl, @params), false); + } + + /// /// Tries to resolve the target redirect url by using the routing rules registered. /// /// The controller name to be redirected to. diff --git a/MonoRail/Castle.MonoRail.Framework/Services/IUrlBuilder.cs b/MonoRail/Castle.MonoRail.Framework/Services/IUrlBuilder.cs index 67401230b..17094a7a5 100644 --- a/MonoRail/Castle.MonoRail.Framework/Services/IUrlBuilder.cs +++ b/MonoRail/Castle.MonoRail.Framework/Services/IUrlBuilder.cs @@ -29,9 +29,9 @@ namespace Castle.MonoRail.Framework.Services { private string area, controller, action; private string domain, subdomain, protocol, basePath, pathInfo; + private string routeName; private int port; private object routeParameters; - private readonly string routeName; private object queryString; private IDictionary customParameters; private bool encodeForLink, createAbsolutePath, useCurrentRouteParams; @@ -40,6 +40,13 @@ namespace Castle.MonoRail.Framework.Services /// /// Initializes a new instance of the class. /// + public UrlBuilderParameters() + { + } + + /// + /// Initializes a new instance of the class. + /// public UrlBuilderParameters(string area, string controller, string action) { this.area = area; @@ -323,6 +330,7 @@ namespace Castle.MonoRail.Framework.Services public string RouteName { get { return routeName; } + set { routeName = value; } } /// -- 2.11.4.GIT