mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-25 19:17:13 +08:00
Fixing redirect on tenants with a URL prefix, fixes #4605
This commit is contained in:
@@ -2,13 +2,15 @@
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Utility.Extensions;
|
||||
using Orchard.Environment.Configuration;
|
||||
|
||||
namespace Orchard.Mvc.Extensions {
|
||||
public static class ControllerExtensions {
|
||||
public static ActionResult RedirectLocal(this Controller controller, string redirectUrl, Func<ActionResult> invalidUrlBehavior) {
|
||||
if (!string.IsNullOrWhiteSpace(redirectUrl) && controller.Request.IsLocalUrl(redirectUrl)) {
|
||||
return new RedirectResult(redirectUrl);
|
||||
return RedirectWithTenantPrefix(redirectUrl, controller);
|
||||
}
|
||||
|
||||
return invalidUrlBehavior != null ? invalidUrlBehavior() : null;
|
||||
}
|
||||
|
||||
@@ -18,10 +20,25 @@ namespace Orchard.Mvc.Extensions {
|
||||
|
||||
public static ActionResult RedirectLocal(this Controller controller, string redirectUrl, string defaultUrl) {
|
||||
if (controller.Request.IsLocalUrl(redirectUrl)) {
|
||||
return new RedirectResult(redirectUrl);
|
||||
return RedirectWithTenantPrefix(redirectUrl, controller);
|
||||
}
|
||||
|
||||
return new RedirectResult(defaultUrl ?? "~/");
|
||||
return RedirectWithTenantPrefix(defaultUrl ?? "~/", controller);
|
||||
}
|
||||
|
||||
private static ActionResult RedirectWithTenantPrefix(string redirectUrl, Controller controller) {
|
||||
if (redirectUrl.StartsWith("~/")) {
|
||||
ShellSettings settings;
|
||||
var context = controller.ControllerContext.GetWorkContext();
|
||||
|
||||
if (context != null &&
|
||||
context.TryResolve<ShellSettings>(out settings) &&
|
||||
!string.IsNullOrWhiteSpace(settings.RequestUrlPrefix)) {
|
||||
redirectUrl = VirtualPathUtility.ToAbsolute(redirectUrl, controller.Request.ApplicationPath.TrimEnd('/') + "/" + settings.RequestUrlPrefix);
|
||||
}
|
||||
}
|
||||
|
||||
return new RedirectResult(redirectUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user