This is out-of-the-box behavior actually, but easily fixed. I implemented this on a site I did recently using the following view found at ~/Views/MacroPartials/Login.cshtml:
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@using System.Web.Mvc.Html
@using ClientDependency.Core.Mvc
@using Umbraco.Web
@using Umbraco.Web.Models
@using Umbraco.Web.Controllers
@{
var loginModel = new LoginModel();
Html.EnableClientValidation();
Html.EnableUnobtrusiveJavaScript();
Html.RequiresJs("/umbraco_client/ui/jquery.js");
Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.min.js");
Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.unobtrusive.min.js");
}
@* NOTE: This RenderJsHere code should be put on your main template page where the rest of your script tags are placed *@
@Html.RenderJsHere()
@using (Html.BeginUmbracoForm<UmbLoginController>("HandleLogin"))
{
if (!Members.IsLoggedIn())
{
@Html.ValidationSummary("loginModel", true)
@Html.HiddenFor(m => loginModel.RedirectUrl)
<fieldset>
@Html.ValidationSummary("loginModel", true)
@Html.LabelFor(m => loginModel.Username)
@Html.TextBoxFor(m => loginModel.Username)
@Html.ValidationMessageFor(m => loginModel.Username)
<br/>
@Html.LabelFor(m => loginModel.Password)
@Html.PasswordFor(m => loginModel.Password)
@Html.ValidationMessageFor(m => loginModel.Password)
<br/>
<a href="forgotten-your-password" class="password-reset">Forgotten your password?</a>
<button>Login</button>
</fieldset>
}
else
{
if (Request.UrlReferrer != null && !Request.UrlReferrer.AbsolutePath.IsNullOrWhiteSpace())
{
Response.Redirect(Request.UrlReferrer.AbsolutePath);
}
else
{
Response.Redirect("/");
}
}
}
So I can't remember how close this is to the view that Umbraco generates but the key points are first checking if the member is logged in:
if (!Members.IsLoggedIn())
{
}
If they are, show the login form, otherwise, they're logged in and you can perform a redirect:
Login is redirecting to Login page
Umbraco 7.7.4
Upon successful login from a role-based protected node, I'm being redirected to the login screen node again.
I can successfully load the protected node if I visit it again after logging in.
Why would it redirect to the login node?
Hi JJ,
This is out-of-the-box behavior actually, but easily fixed. I implemented this on a site I did recently using the following view found at
~/Views/MacroPartials/Login.cshtml
:So I can't remember how close this is to the view that Umbraco generates but the key points are first checking if the member is logged in:
If they are, show the login form, otherwise, they're logged in and you can perform a redirect:
This checks to see if there was a referrer set, if so, redirects to that page, otherwise redirects off to the homepage.
Hope that helps!
Thanks, works perfect.
Odd "default" behaviour though, but hey ho!
is working on a reply...