我正在研究一个ASP.Net应用程序,我正在计划实现应用程序的管理员可以模拟用户并以该用户身份使用该应用程序的功能。如果有人有一个想法或经验,这将是非常有益的。顺便说一句,我可以使用cookie来存储模拟用户数据并将其检索到应用程序。用户ASP.NET模拟
非常感谢。
更新 我发现这个解决方案http://tech.trailmax.info/2014/06/user-impersonation-with-asp-net-identity-2/为我的项目,但现在我面临一些其他问题。这里还有一个来自代码的示例,其中出现错误。
public async Task ImpersonateUserAsync(string userName)
{
var context = HttpContext.Current;
var originalUsername = context.User.Identity.Name;
var impersonatedUser = await userManager.FindByNameAsync(userName);
var impersonatedIdentity = await userManager.CreateIdentityAsync(impersonatedUser, DefaultAuthenticationTypes.ApplicationCookie);
impersonatedIdentity.AddClaim(new Claim("UserImpersonation", "true"));
impersonatedIdentity.AddClaim(new Claim("OriginalUsername", originalUsername));
var authenticationManager = context.GetOwinContext().Authentication;
authenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
authenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = false }, impersonatedIdentity);
}
错误是由于这条线var authenticationManager = context.GetOwinContext().Authentication;
。此处还有错误消息。使用指令
CS1061 C#“的HttpContext”不包含 “GetOwinContext”的定义和没有扩展方法“GetOwinContext”接受类型“的HttpContext”的 第一个参数可以找到(是否缺少 或一个装配参考?)
任何想法我失踪。
此链接可能会帮助你... https://www.codeproject.com/Tips/520341/Implement-Impersonation-in-ASP-NET –