Copied to clipboard

Flag this post as spam?

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

  • iNETZO 93 posts 412 karma points
    Mar 10, 2018 @ 16:48

    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!


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

    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");
  • iNETZO 93 posts 412 karma points
    May 04, 2018 @ 06:13

    This works great, thanks!

Please Sign in or register to post replies

Write your reply to: