Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sören Deger 733 posts 2844 karma points c-trib
    Feb 05, 2014 @ 14:37
    Sören Deger
    0

    Auto User login with razor?

    Hello,

    is it possible to login an user automaticaly with razor? On the protected redirect page after member login I have a razor script with this code:

             Member m = Member.GetCurrentMember();
              var ump = new umbraco.providers.UsersMembershipProvider();
    if (ump.ValidateUser(m.LoginName, m.Password))
    { <p>OK</p>
    } else {
    <p>ERROR</p>
    }

    This works, but the user is not logged on. I have any members and users with the same loginname and password. I want that the user is automatically logged on when the member logs and the userloginname exist.

    Has anyone a snippet or idea to solve this?


    Best regards

    Sören

  • Jeroen Breuer 4909 posts 12266 karma points MVP 6x admin c-trib
    Feb 05, 2014 @ 14:50
    Jeroen Breuer
    0

    This example might help:

    string username = Request["username"];
    string password = Request["password"];
    if (Membership.ValidateUser(username, password))
    {
        FormsAuthentication.SetAuthCookie(username, true);
    
        Response.Redirect("/");
    }

    Jeroen

  • Sören Deger 733 posts 2844 karma points c-trib
    Feb 06, 2014 @ 04:48
    Sören Deger
    0

    Hi Jeroen,

    thank you. The ValidateUser works, but it will set no authentication. If I set the redirect to /umbraco/ I'm not logged on.

     

    Sören

  • Jeroen Breuer 4909 posts 12266 karma points MVP 6x admin c-trib
    Feb 06, 2014 @ 12:05
    Jeroen Breuer
    0

    Hello,

    Are you talking about members of users?

    Users can login the Umbraco backend and members in a protected part of the website.

    My example is for members.

    Jeroen

  • Sören Deger 733 posts 2844 karma points c-trib
    Feb 06, 2014 @ 13:09
    Sören Deger
    0

    Hello,

    thank you. I know the difference between members and users. Apologies that I have not expressed myself correctly.

    I try to login on a page with a member. I will then be redirected to a page on which a script is to be called that automatically logs the user of the same name in the backend. 

    So I only need a snippet for the frontend with razor how I can an user loged on in the backend.
     

    But I have now found another functioning alternative. The reverse is also practical for me: After I logged on in backend I logging on the member in the frontend. In addition I have now created a UserControl for the "welcome dashboard" in backend which automatically logs the member with the same name in the frontend after user logging :-)

    Sören

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies