Actually I could not get that working, guess the current node id is pointing to login-page and not the requested page at the time for the macro processing(?).
But I have now been fiddling around with the login some more, and made it a little cleaner with the new possibilities in 4.7. I would be very glad if someone could help me out with some testing (it does work in my installation):
I'm using "Gist" for the source until it's tested enough, easier to edit it there (and easier to copy-paste from there too):
Awesome package, this makes working with membership so much easier! How would I configure it to redirect to the protected page instead of staying on the current one? I have the login form on every page of the site in the header...
@{ var isSubmitLogin = (IsPost && Request["submit"]=="login"); var isSubmitLogout = (IsPost && Request["submit"]=="logout"); var currentUser = Membership.GetUser(); var requestedUrl = Request.Url.PathAndQuery.ToString(); // Model.Url; if (Request["ReturnUrl"]!=null) { requestedUrl = Request["ReturnUrl"]; }
if (currentUser!=null) { if (!isSubmitLogout) { @Message("Logged in : " + currentUser.UserName) @LogoutForm() } else { FormsAuthentication.SignOut(); FormsAuthentication.RedirectToLoginPage(); } }
if (currentUser==null) { if (!isSubmitLogin) { @LoginForm() } else { string username=Request["username"]; string password=Request["password"]; if (Membership.ValidateUser(username, password)) { // RedirectFromLoginPage does not work that good within the Umbraco context // FormsAuthentication.RedirectFromLoginPage(username, true);
Stay on protected page after login
To make login stay on the current page after login - and not redirect to a default page, change the following part of the script:
isn't it "safer" to use:
HttpContext.Current.Response.Redirect(umbraco.library.NiceUrl(Node.GetCurrent().Id));
to reset possible querystring values etc?
I don't like using RawUrl :)
Hi!
Actually I could not get that working, guess the current node id is pointing to login-page and not the requested page at the time for the macro processing(?).
But I have now been fiddling around with the login some more, and made it a little cleaner with the new possibilities in 4.7. I would be very glad if someone could help me out with some testing (it does work in my installation):
I'm using "Gist" for the source until it's tested enough, easier to edit it there (and easier to copy-paste from there too):
https://gist.github.com/874194
To use it - just paste the code into a template within <umbraco:macro runat="server" language="razor">...</umbraco:macro>,
or create a macro.
Awesome package, this makes working with membership so much easier! How would I configure it to redirect to the protected page instead of staying on the current one? I have the login form on every page of the site in the header...
Thanks for any help!
Amir
Glad you like it :)
Hm I will have to try it with your configuration. Did you use the code from the gist-link?
Yep! Heres my code if it helps.
is working on a reply...