Copied to clipboard

Flag this post as spam?

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


  • iNETZO 136 posts 499 karma points c-trib
    Mar 10, 2018 @ 16:48
    iNETZO
    0

    Login member and user via FormAuthentication at once

    Hi everybody,

    I'm working on an intranetproject in Umbraco. I use FormAuthentication to login the members. What i want to do is after a member is succesfull authenticated, is to check if there is a user account with the same username as the member and login this backenduser as well. The member authenticates by Active Directory username and password (via a surfacecontroller).

    The memberauthentication works well but I can not get the user authenticated after succesfull authenticating the member.

    I have tried to do this with the code below but it doesn't work because when navigating to "/umbraco" the user still gets the loginform.

                    var user = Services.UserService.GetByUsername(model.Username);
                    if (user != null)
                    {
                        new HttpContextWrapper(System.Web.HttpContext.Current).CreateUmbracoAuthTicket(
                            new UserData(Guid.NewGuid().ToString())
                            {
                                Culture = user.Language,
                                Id = user.Id,
                                RealName = user.Name,
                                Username = user.Username
                            });
                    }
    

    When using the code above, there is a cookie created called "UMB_UCONTEXT". Did I forgot something or is there another way to authenticate users programmatically only by username?
    Thanks in avance!

    iNETZO

  • SSA 2 posts 92 karma points
    Apr 26, 2018 @ 12:38
    SSA
    100

    The following code should work, it uses the built in Umbraco class 'WebSecurity'.

    var ws = new WebSecurity(HttpContext, ApplicationContext);
    var user = Services.UserService.GetByUsername("username");
    ws.PerformLogin(user.Id);
    
  • iNETZO 136 posts 499 karma points c-trib
    May 04, 2018 @ 06:13
    iNETZO
    0

    This works great, thanks!

  • 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