mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Fix for issue [workitem:16371]
Removing FollowReturnUrl filter because it always gets executed and does not allow actions to return other view or redirect to other locations. Replacing filter with a Controller extension method called ReturnUrlRedirect which parses the ReturnUrl in the querystring and returns a RedirectFilter action with that Url.
This commit is contained in:
@@ -7,7 +7,6 @@ using Orchard.Blogs.ViewModels;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Mvc.AntiForgery;
|
||||
using Orchard.Mvc.FollowReturnUrl;
|
||||
using Orchard.Mvc.Results;
|
||||
using Orchard.UI.Admin;
|
||||
using Orchard.UI.Notify;
|
||||
@@ -101,7 +100,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[HttpPost, ActionName("Edit"), FollowReturnUrl]
|
||||
[HttpPost, ActionName("Edit")]
|
||||
public ActionResult EditPOST(string blogSlug, int postId) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.EditBlogPost, T("Couldn't edit blog post")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
@@ -7,7 +7,6 @@ using JetBrains.Annotations;
|
||||
using Orchard.Localization;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Mvc.AntiForgery;
|
||||
using Orchard.Mvc.FollowReturnUrl;
|
||||
using Orchard.Mvc.Results;
|
||||
using Orchard.Pages.Drivers;
|
||||
using Orchard.Pages.Models;
|
||||
@@ -174,7 +173,7 @@ namespace Orchard.Pages.Controllers {
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[HttpPost, ActionName("Edit"), FollowReturnUrl]
|
||||
[HttpPost, ActionName("Edit")]
|
||||
public ActionResult EditPOST(int id) {
|
||||
var page = _pageService.GetPageOrDraft(id);
|
||||
if (page == null)
|
||||
|
@@ -5,7 +5,7 @@ using System.Security.Principal;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Security;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Mvc.FollowReturnUrl;
|
||||
using Orchard.Mvc.Extensions;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
using Orchard.Security;
|
||||
using Orchard.Users.Services;
|
||||
@@ -52,7 +52,7 @@ namespace Orchard.Users.Controllers {
|
||||
return View("LogOn", new LogOnViewModel {Title = "Log On"});
|
||||
}
|
||||
|
||||
[HttpPost, FollowReturnUrl]
|
||||
[HttpPost]
|
||||
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings",
|
||||
Justification = "Needs to take same parameter type as Controller.Redirect()")]
|
||||
public ActionResult LogOn(string userName, string password, bool rememberMe) {
|
||||
@@ -63,14 +63,13 @@ namespace Orchard.Users.Controllers {
|
||||
|
||||
_authenticationService.SignIn(user, rememberMe);
|
||||
|
||||
return Redirect("~/");
|
||||
return this.ReturnUrlRedirect();
|
||||
}
|
||||
|
||||
[FollowReturnUrl]
|
||||
public ActionResult LogOff() {
|
||||
_authenticationService.SignOut();
|
||||
|
||||
return Redirect("~/");
|
||||
return this.ReturnUrlRedirect();
|
||||
}
|
||||
|
||||
int MinPasswordLength {
|
||||
|
39
src/Orchard/Mvc/Extensions/ControllerExtensions.cs
Normal file
39
src/Orchard/Mvc/Extensions/ControllerExtensions.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Mvc.Results;
|
||||
|
||||
namespace Orchard.Mvc.Extensions {
|
||||
public static class ControllerExtensions {
|
||||
public static RedirectResult ReturnUrlRedirect(this Controller controller) {
|
||||
var request = controller.HttpContext.Request;
|
||||
Uri returnUrl = null;
|
||||
try
|
||||
{
|
||||
returnUrl = new Uri(request.QueryString["ReturnUrl"]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
try
|
||||
{
|
||||
returnUrl =
|
||||
new Uri(string.Format("{0}://{1}{2}{3}", request.Url.Scheme, request.Url.Host,
|
||||
request.Url.Port != 80 ? ":" + request.Url.Port : "",
|
||||
request.QueryString["ReturnUrl"]));
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
if (returnUrl != null &&
|
||||
returnUrl.Scheme == request.Url.Scheme &&
|
||||
returnUrl.Port == request.Url.Port &&
|
||||
returnUrl.Host == request.Url.Host)
|
||||
{
|
||||
return new RedirectResult(returnUrl.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
return new RedirectResult("~/");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,8 +0,0 @@
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Orchard.Mvc.FollowReturnUrl {
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public class FollowReturnUrlAttribute : FilterAttribute {
|
||||
}
|
||||
}
|
@@ -1,42 +0,0 @@
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Mvc.Filters;
|
||||
|
||||
namespace Orchard.Mvc.FollowReturnUrl {
|
||||
public class FollowReturnUrlFilter : FilterProvider, IActionFilter {
|
||||
public void OnActionExecuting(ActionExecutingContext filterContext) {
|
||||
}
|
||||
|
||||
public void OnActionExecuted(ActionExecutedContext filterContext) {
|
||||
var attributes =
|
||||
(FollowReturnUrlAttribute[])
|
||||
filterContext.ActionDescriptor.GetCustomAttributes(typeof (FollowReturnUrlAttribute), false);
|
||||
|
||||
if (attributes.Length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
var request = filterContext.HttpContext.Request;
|
||||
Uri returnUrl = null;
|
||||
try {
|
||||
returnUrl = new Uri(request.QueryString["ReturnUrl"]);
|
||||
}
|
||||
catch {
|
||||
try {
|
||||
returnUrl =
|
||||
new Uri(string.Format("{0}://{1}{2}{3}", request.Url.Scheme, request.Url.Host,
|
||||
request.Url.Port != 80 ? ":" + request.Url.Port : "",
|
||||
request.QueryString["ReturnUrl"]));
|
||||
}
|
||||
catch {}
|
||||
}
|
||||
|
||||
if (returnUrl != null &&
|
||||
returnUrl.Scheme == request.Url.Scheme &&
|
||||
returnUrl.Port == request.Url.Port &&
|
||||
returnUrl.Host == request.Url.Host) {
|
||||
filterContext.Result = new RedirectResult(returnUrl.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -156,10 +156,9 @@
|
||||
<Compile Include="Extensions\StringExtensions.cs" />
|
||||
<Compile Include="Extensions\UriExtensions.cs" />
|
||||
<Compile Include="Mvc\AntiForgery\ValidateAntiForgeryTokenOrchardAttribute.cs" />
|
||||
<Compile Include="Mvc\FollowReturnUrl\FollowReturnUrlFilter.cs" />
|
||||
<Compile Include="Mvc\Extensions\ControllerExtensions.cs" />
|
||||
<Compile Include="Mvc\Html\FileRegistrationContextExtensions.cs" />
|
||||
<Compile Include="Mvc\Extensions\UrlHelperExtensions.cs" />
|
||||
<Compile Include="Mvc\FollowReturnUrl\FollowReturnUrlAttribute.cs" />
|
||||
<Compile Include="Mvc\ViewModels\AdaptedViewModel.cs" />
|
||||
<Compile Include="Mvc\ViewUserControl.cs">
|
||||
<SubType>ASPXCodeBehind</SubType>
|
||||
@@ -366,6 +365,7 @@
|
||||
<Compile Include="Storage\IStorageFolder.cs" />
|
||||
<Compile Include="Storage\IStorageProvider.cs" />
|
||||
<Compile Include="UI\Zones\ZoneManager.cs" />
|
||||
<Compile Include="Utility\FollowReturnUrl.cs" />
|
||||
<Compile Include="Utility\Position.cs" />
|
||||
<Compile Include="Utility\Reflect.cs" />
|
||||
<Compile Include="Utility\ReflectOn.cs" />
|
||||
|
Reference in New Issue
Block a user