Skip to content

Instantly share code, notes, and snippets.

@mesuttalebi
Created October 19, 2019 12:56
Show Gist options
  • Save mesuttalebi/c68eef7ff54256190f5f0f487a69acc7 to your computer and use it in GitHub Desktop.
Save mesuttalebi/c68eef7ff54256190f5f0f487a69acc7 to your computer and use it in GitHub Desktop.
Imporsonation using Asp.net mvc 5 Identity
[Authorize(Roles = "Administrator")]
public ActionResult Impersonate(string email)
{
var impersonatedUser = UserManager.FindByEmail(email);
var impersonatedIdentity = UserManager.CreateIdentity(impersonatedUser, DefaultAuthenticationTypes.ApplicationCookie);
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = false }, impersonatedIdentity);
return RedirectToAction("Index", "Home");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment