Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何刷新cookie以反映用户更改电子邮件?_C#_Vb.net_Asp.net Mvc 4_Forms Authentication_Simplemembership - Fatal编程技术网

C# 如何刷新cookie以反映用户更改电子邮件?

C# 如何刷新cookie以反映用户更改电子邮件?,c#,vb.net,asp.net-mvc-4,forms-authentication,simplemembership,C#,Vb.net,Asp.net Mvc 4,Forms Authentication,Simplemembership,我正在使用WebSecurity和SimpleMembershipProvider让用户登录 用户可以更改他们的电子邮件 Dim memberId为整数=1 作为UsersContext的Dim上下文=新UsersContext 将userProfile设置为userProfile= context.UserProfiles.Where(函数(f)f.UserId=memberId.SingleOrDefault() '更改前发送电子邮件:”a@a.com" userProfile.UserNa

我正在使用WebSecurity和SimpleMembershipProvider让用户登录

用户可以更改他们的电子邮件

Dim memberId为整数=1
作为UsersContext的Dim上下文=新UsersContext
将userProfile设置为userProfile=
context.UserProfiles.Where(函数(f)f.UserId=memberId.SingleOrDefault()
'更改前发送电子邮件:”a@a.com"
userProfile.UserName=”b@b.com"
context.SaveChanges()
但是,更新之后,HttpContext仍然将用户报告为其旧电子邮件

“名称为”a@a.com“但应该是”b@b.com"
HttpContext.User.Identity.Name
起初,我以为我可以让用户退出并重新登录

WebSecurity.Logout()
'但是我没有用户的密码
WebSecurity.Login(“b@b.com", "???")
如何以某种方式刷新身份验证cookie以反映用户更改其登录详细信息?

OP here。这是一种(丑陋的?)方法:

Dim newEmail As String=”b@b.com"
Dim票证为FormsAuthentication票证=
新建FormsAuthenticationTicket(新建电子邮件,错误,FormsAuthentication.Timeout.Minutes)
身份为IIdentity的Dim标识=新表单实体(票据)
HttpContext.Current.User=新角色原则(标识)
FormsAuthentication.SetAuthCookie(newEmail,False)
它很好用,但看起来有点难看。这迫使我的应用程序依赖于
表单身份验证
(正确吗?)

@戴夫


您是否认为我应该使用此代码,但将其放入我自己的自定义
MemershipProvider
(是这样吗?是否由
会员资格提供商处理此问题?

要通过会员资格更改cookie,您似乎必须将用户注销并重新登录

此时您面临的困境是如何在没有密码的情况下登录用户


最好的方法似乎是在更改用户名时询问用户的密码。这对它有一种合理的感觉,并为您提供密码。

注销用户并使用新用户名重新登录em,但我使用的是
WebSecurity
Login
方法需要传递用户名和密码。有什么想法吗?是的。如果没有密码你做不到,它会变得一团糟。。。我也会考虑的:P我在想唯一的办法是制作我自己的会员资格提供商或者直接操作cookies。longshot。。。在电子邮件更改期间(在确认用户身份的背景下——增加了安全性)您可以请求密码吗?它并没有那个么难看。但我同意它看起来并不干燥。我认为这是很好的第一步。您可以创建自己的提供商来简化此过程,但这似乎与避免此问题的投资不成比例。虽然我的解决方案有效,但我想我会向任何寻求问题答案的人推荐此解决方案。如果您打算允许用户更改其登录详细信息(即用户名/电子邮件),那么同时需要输入密码是一个很好的安全措施。然后,您可以使用他们输入的用户名和密码将他们注销,然后重新登录。