This is what I do, I have a list control which lists the members in the front end if the logged in member is an Administrator, they can select a member to impersonate.
public IActionResult Impersonate([FromQuery]string memberId)
{
//Get the member to impersonate
var member = _memberService.GetById(Convert.ToInt32(memberId));
var signinuser = _memberManager.FindByNameAsync(member.Username).Result;
//Get the currently logged in
var currentUser = _memberManager.GetCurrentMemberAsync().Result;
var currMember = _memberService.GetByKey(currentUser.Key);
//signout currentuser
_signInManager.SignOutAsync();
//Sign in as impersonated user
_signInManager.SignInAsync(signinuser,false);
HttpContext.Session.SetString("portalImpersonate", currentUser.Id);
return CurrentUmbracoPage();
}
I also added a session variable which is set to currentUser.Id to indicate the user was impersonating someone, then added code to my logout method which checks the session variable and if set, logs you back in as the previous user.
Umbraco 10 - Member Impersonation
Hello,
I'm trying to impersonate a member and login as them via a click on a "Login as Member" button in the backoffice that redirects to the frontend.
I found this line of code below but can't seem to find the equivalent in Umbraco 10 :
I tried to implement the code below to no avail :
Has anyone had any luck with a similar situation? Some help on this would be much appreciated.
Cheers.
This is what I do, I have a list control which lists the members in the front end if the logged in member is an Administrator, they can select a member to impersonate.
Hi Huw,
Implemented your solution yesterday and it worked perfectly. Really appreciate your help on this one. Have a great rest of the week.
Glad it helped.
I also added a session variable which is set to currentUser.Id to indicate the user was impersonating someone, then added code to my logout method which checks the session variable and if set, logs you back in as the previous user.
is working on a reply...