I wanted to post this as a comment, but I'm too long. I needed a dynamic redirect for one of my applications and used the following solution (it uses a controller that called it instead of the static URL in web.config). By testing this example, you fix the problem. But I canβt understand why. Perhaps this will lead you to the right path, or someone else may clarify.
using System.Web.Mvc; using System.Web.Routing; namespace MvcApplication1.App_Start { public class LoginRequiredAttribute : AuthorizeAttribute { public override void OnAuthorization(AuthorizationContext filterContext) { base.OnAuthorization(filterContext); if (filterContext.Result is HttpUnauthorizedResult) { filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { { "controller", filterContext.RouteData.Values[ "controller" ] }, { "action", "Login" }, { "ReturnUrl", filterContext.HttpContext.Request.RawUrl } }); } } } }
Then just change the action to use the new attribute:
[LoginRequired] public ActionResult TestMe()
source share