Added overloads to RedirectToUmbracoPage methods to allow passing of a querystring
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
@@ -14,8 +17,10 @@ namespace Umbraco.Web.Mvc
|
||||
{
|
||||
private IPublishedContent _publishedContent;
|
||||
private readonly int _pageId;
|
||||
private NameValueCollection _queryStringValues;
|
||||
private readonly UmbracoContext _umbracoContext;
|
||||
private string _url;
|
||||
|
||||
public string Url
|
||||
{
|
||||
get
|
||||
@@ -24,7 +29,7 @@ namespace Umbraco.Web.Mvc
|
||||
|
||||
if (PublishedContent == null)
|
||||
{
|
||||
throw new InvalidOperationException("Cannot redirect, no entity was found for id " + _pageId);
|
||||
throw new InvalidOperationException(string.Format("Cannot redirect, no entity was found for id {0}", _pageId));
|
||||
}
|
||||
|
||||
var result = _umbracoContext.RoutingContext.UrlProvider.GetUrl(PublishedContent.Id);
|
||||
@@ -34,7 +39,7 @@ namespace Umbraco.Web.Mvc
|
||||
return _url;
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("Could not route to entity with id " + _pageId + ", the NiceUrlProvider could not generate a URL");
|
||||
throw new InvalidOperationException(string.Format("Could not route to entity with id {0}, the NiceUrlProvider could not generate a URL", _pageId));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -61,6 +66,26 @@ namespace Umbraco.Web.Mvc
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new RedirectToUmbracoResult
|
||||
/// </summary>
|
||||
/// <param name="pageId"></param>
|
||||
/// <param name="queryStringValues"></param>
|
||||
public RedirectToUmbracoPageResult(int pageId, NameValueCollection queryStringValues)
|
||||
: this(pageId, queryStringValues, UmbracoContext.Current)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new RedirectToUmbracoResult
|
||||
/// </summary>
|
||||
/// <param name="pageId"></param>
|
||||
/// <param name="queryString"></param>
|
||||
public RedirectToUmbracoPageResult(int pageId, string queryString)
|
||||
: this(pageId, queryString, UmbracoContext.Current)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new RedirectToUmbracoResult
|
||||
/// </summary>
|
||||
@@ -70,6 +95,63 @@ namespace Umbraco.Web.Mvc
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new RedirectToUmbracoResult
|
||||
/// </summary>
|
||||
/// <param name="publishedContent"></param>
|
||||
/// <param name="queryStringValues"></param>
|
||||
public RedirectToUmbracoPageResult(IPublishedContent publishedContent, NameValueCollection queryStringValues)
|
||||
: this(publishedContent, queryStringValues, UmbracoContext.Current)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new RedirectToUmbracoResult
|
||||
/// </summary>
|
||||
/// <param name="queryString"></param>
|
||||
/// <param name="queryStringValues"></param>
|
||||
public RedirectToUmbracoPageResult(IPublishedContent publishedContent, string queryString)
|
||||
: this(publishedContent, queryString, UmbracoContext.Current)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new RedirectToUmbracoResult
|
||||
/// </summary>
|
||||
/// <param name="pageId"></param>
|
||||
/// <param name="umbracoContext"></param>
|
||||
public RedirectToUmbracoPageResult(int pageId, UmbracoContext umbracoContext)
|
||||
{
|
||||
_pageId = pageId;
|
||||
_umbracoContext = umbracoContext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new RedirectToUmbracoResult
|
||||
/// </summary>
|
||||
/// <param name="pageId"></param>
|
||||
/// <param name="queryStringValues"></param>
|
||||
/// <param name="umbracoContext"></param>
|
||||
public RedirectToUmbracoPageResult(int pageId, NameValueCollection queryStringValues, UmbracoContext umbracoContext)
|
||||
{
|
||||
_pageId = pageId;
|
||||
_queryStringValues = queryStringValues;
|
||||
_umbracoContext = umbracoContext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new RedirectToUmbracoResult
|
||||
/// </summary>
|
||||
/// <param name="pageId"></param>
|
||||
/// <param name="queryString"></param>
|
||||
/// <param name="umbracoContext"></param>
|
||||
public RedirectToUmbracoPageResult(int pageId, string queryString, UmbracoContext umbracoContext)
|
||||
{
|
||||
_pageId = pageId;
|
||||
_queryStringValues = ParseQueryString(queryString);
|
||||
_umbracoContext = umbracoContext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new RedirectToUmbracoResult
|
||||
/// </summary>
|
||||
@@ -82,16 +164,33 @@ namespace Umbraco.Web.Mvc
|
||||
_umbracoContext = umbracoContext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new RedirectToUmbracoResult
|
||||
/// </summary>
|
||||
/// <param name="pageId"></param>
|
||||
/// <param name="umbracoContext"></param>
|
||||
public RedirectToUmbracoPageResult(int pageId, UmbracoContext umbracoContext)
|
||||
{
|
||||
_pageId = pageId;
|
||||
_umbracoContext = umbracoContext;
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates a new RedirectToUmbracoResult
|
||||
/// </summary>
|
||||
/// <param name="publishedContent"></param>
|
||||
/// <param name="queryStringValues"></param>
|
||||
/// <param name="umbracoContext"></param>
|
||||
public RedirectToUmbracoPageResult(IPublishedContent publishedContent, NameValueCollection queryStringValues, UmbracoContext umbracoContext)
|
||||
{
|
||||
_publishedContent = publishedContent;
|
||||
_pageId = publishedContent.Id;
|
||||
_queryStringValues = queryStringValues;
|
||||
_umbracoContext = umbracoContext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new RedirectToUmbracoResult
|
||||
/// </summary>
|
||||
/// <param name="publishedContent"></param>
|
||||
/// <param name="queryString"></param>
|
||||
/// <param name="umbracoContext"></param>
|
||||
public RedirectToUmbracoPageResult(IPublishedContent publishedContent, string queryString, UmbracoContext umbracoContext)
|
||||
{
|
||||
_publishedContent = publishedContent;
|
||||
_pageId = publishedContent.Id;
|
||||
_queryStringValues = ParseQueryString(queryString);
|
||||
_umbracoContext = umbracoContext;
|
||||
}
|
||||
|
||||
public override void ExecuteResult(ControllerContext context)
|
||||
{
|
||||
@@ -103,10 +202,26 @@ namespace Umbraco.Web.Mvc
|
||||
}
|
||||
|
||||
var destinationUrl = UrlHelper.GenerateContentUrl(Url, context.HttpContext);
|
||||
|
||||
if (_queryStringValues != null && _queryStringValues.Count > 0)
|
||||
{
|
||||
destinationUrl = destinationUrl += "?" + string.Join("&",
|
||||
_queryStringValues.AllKeys.Select(x => x + "=" + HttpUtility.UrlEncode(_queryStringValues[x])));
|
||||
}
|
||||
|
||||
context.Controller.TempData.Keep();
|
||||
|
||||
context.HttpContext.Response.Redirect(destinationUrl, endResponse: false);
|
||||
}
|
||||
|
||||
private NameValueCollection ParseQueryString(string queryString)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(queryString))
|
||||
{
|
||||
return HttpUtility.ParseQueryString(queryString);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using System.Web.Routing;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Web.Security;
|
||||
using System.Collections.Specialized;
|
||||
|
||||
namespace Umbraco.Web.Mvc
|
||||
{
|
||||
@@ -56,6 +57,28 @@ namespace Umbraco.Web.Mvc
|
||||
return new RedirectToUmbracoPageResult(pageId, UmbracoContext);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects to the Umbraco page with the given id and passes provided querystring
|
||||
/// </summary>
|
||||
/// <param name="pageId"></param>
|
||||
/// <param name="queryStringValues"></param>
|
||||
/// <returns></returns>
|
||||
protected RedirectToUmbracoPageResult RedirectToUmbracoPage(int pageId, NameValueCollection queryStringValues)
|
||||
{
|
||||
return new RedirectToUmbracoPageResult(pageId, queryStringValues, UmbracoContext);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects to the Umbraco page with the given id and passes provided querystring
|
||||
/// </summary>
|
||||
/// <param name="pageId"></param>
|
||||
/// <param name="queryString"></param>
|
||||
/// <returns></returns>
|
||||
protected RedirectToUmbracoPageResult RedirectToUmbracoPage(int pageId, string queryString)
|
||||
{
|
||||
return new RedirectToUmbracoPageResult(pageId, queryString, UmbracoContext);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects to the Umbraco page with the given id
|
||||
/// </summary>
|
||||
@@ -66,6 +89,28 @@ namespace Umbraco.Web.Mvc
|
||||
return new RedirectToUmbracoPageResult(publishedContent, UmbracoContext);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects to the Umbraco page with the given id and passes provided querystring
|
||||
/// </summary>
|
||||
/// <param name="publishedContent"></param>
|
||||
/// <param name="queryStringValues"></param>
|
||||
/// <returns></returns>
|
||||
protected RedirectToUmbracoPageResult RedirectToUmbracoPage(IPublishedContent publishedContent, NameValueCollection queryStringValues)
|
||||
{
|
||||
return new RedirectToUmbracoPageResult(publishedContent, queryStringValues, UmbracoContext);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects to the Umbraco page with the given id and passes provided querystring
|
||||
/// </summary>
|
||||
/// <param name="publishedContent"></param>
|
||||
/// <param name="queryString"></param>
|
||||
/// <returns></returns>
|
||||
protected RedirectToUmbracoPageResult RedirectToUmbracoPage(IPublishedContent publishedContent, string queryString)
|
||||
{
|
||||
return new RedirectToUmbracoPageResult(publishedContent, queryString, UmbracoContext);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects to the currently rendered Umbraco page
|
||||
/// </summary>
|
||||
@@ -75,6 +120,25 @@ namespace Umbraco.Web.Mvc
|
||||
return new RedirectToUmbracoPageResult(CurrentPage, UmbracoContext);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects to the currently rendered Umbraco page and passes provided querystring
|
||||
/// </summary>
|
||||
/// <param name="queryStringValues"></param>
|
||||
/// <returns></returns>
|
||||
protected RedirectToUmbracoPageResult RedirectToCurrentUmbracoPage(NameValueCollection queryStringValues)
|
||||
{
|
||||
return new RedirectToUmbracoPageResult(CurrentPage, queryStringValues, UmbracoContext);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects to the currently rendered Umbraco page and passes provided querystring
|
||||
/// </summary>
|
||||
/// <param name="queryStringValues"></param>
|
||||
/// <returns></returns>
|
||||
protected RedirectToUmbracoPageResult RedirectToCurrentUmbracoPage(string queryString)
|
||||
{
|
||||
return new RedirectToUmbracoPageResult(CurrentPage, queryString, UmbracoContext);
|
||||
}
|
||||
/// <summary>
|
||||
/// Redirects to the currently rendered Umbraco URL
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user