如何在MVC ASP.NET Identity 2.0中添加模拟 [英] How do I add impersonation in MVC ASP.NET Identity 2.0

查看:42
本文介绍了如何在MVC ASP.NET Identity 2.0中添加模拟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在mvc identity 2.0上添加用户模拟,我看到有人使用它:

I am wondering how I add user impersonation on mvc identity 2.0, I seen some people using this:

FormsAuthentication.SignOut();
FormsAuthentication.SetAuthCookie(user.UserName, false);

这对我不起作用,甚至我退出时也不会退出:

This wont work for me it wont even sign out I use :

AuthenticationManager.SignOut() 

那么我该如何做呢?我有一个管理面板,该面板列出了用户,我得到了userId或userName,我该怎么办?我从未使用过Claims,所以我不太了解它,我不需要回复给他们现在只能注销的用户.

So how do I go along doing this I have admin panel what lists users, I get the userId or userName, what exactly do I have to do? I have never used Claims so I dont understand it much I wont need to revert back to user they can just logout for now.

推荐答案

以下是任何遇到此问题的人的解决方案-:

Here is the solution for anyone who else is having this issue - :

var user = _db.AspNetUsers.Single(a => a.Id == id);

var impersonatedUser = UserManager.FindByName(user.Email);

var impersonatedIdentity = UserManager.CreateIdentity(impersonatedUser, DefaultAuthenticationTypes.ApplicationCookie);

AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = false }, impersonatedIdentity);

这篇关于如何在MVC ASP.NET Identity 2.0中添加模拟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆