将asp.net身份版本1.0.0-rc1与Entity Framework 6.0.0-rc1(Visual Studio 2013 RC附带的那些)一起使用.
试图让用户有机会改变他们的UserName.似乎没有功能AuthenticationIdentityManager,所以我使用EF更改数据(获取当前用户的User对象,更改UserName并保存更改).
问题是认证cookie保持不变,下一个请求失败,因为没有这样的用户.
在过去的表单身份验证中,我使用以下代码来解决此问题.
var formsAuthCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
var isPersistent = FormsAuthentication.Decrypt(formsAuthCookie.Value).IsPersistent;
FormsAuthentication.SetAuthCookie(newUserName, isPersistent);
Run Code Online (Sandbox Code Playgroud)
我该怎么做asp.net身份更新cookie?
UPDATE
以下代码似乎更新了身份验证cookie.
var identity = new ClaimsIdentity(User.Identity);
identity.RemoveClaim(identity.FindFirst(identity.NameClaimType));
identity.AddClaim(new Claim(identity.NameClaimType, newUserName));
AuthenticationManager.AuthenticationResponseGrant = new AuthenticationResponseGrant
(new ClaimsPrincipal(identity), new AuthenticationProperties {IsPersistent = false});
Run Code Online (Sandbox Code Playgroud)
剩下的问题是:如何IsPersistent从当前身份验证cookie中提取值?
我正在使用带有身份2.1.0和VS2013 U4的ASP.NET MVC 5项目.我想在注册期间向用户添加声明,以便存储在db中.这些声明代表用户自定义属性.
当我为管理员创建一个用于创建/编辑/删除用户的网页时,我仍然使用create method AccountController来创建用户,但我不想登录该用户.如何将这些声明添加到用户?
我有两个与此相关的问题:
1)我需要使用Asp.Net Identity 2将一些远程用户添加/删除后,使invalid.AspNet.ApplicationCookie无效.我尝试使用UpdateSecurityStamp,但由于没有更改密码或用户名,因此SecurityStamp保持不变.当我使用ApplicationRoleManger时,我可以看到用户角色已更新,但在User.Identity声明中,它们保持不变.
2).AspNet.ApplicationCookie验证如何工作以及如何访问它?
我试图使用此代码,但没有任何效果
什么是ASP.NET Identity的IUserSecurityStampStore <TUser>接口?
更新:这是我的Cookie验证设置:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromSeconds(0),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)),
OnApplyRedirect = ctx =>
{
if (!IsApiRequest(ctx.Request))
{
ctx.Response.Redirect(ctx.RedirectUri);
}
}
}
});
Run Code Online (Sandbox Code Playgroud)
我可以看到user.GenerateUserIdentityAsync(manager)仅在登录时被命中.
我们的想法是为ASP.NET MVC 5和ASP.NET Identity中的不同用户角色设置不同的会话超时值.
有可能吗?
asp.net-mvc roles session-timeout asp.net-mvc-5 asp.net-identity