如何使用mvc4和simplemembership改变用户名 [英] How to change username using mvc4 and simplemembership

查看:240
本文介绍了如何使用mvc4和simplemembership改变用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么你不能改变一个simplemembership用户名。我试过

Why is it that you can't change a simplemembership username. I've tried

MembershipUser memUser = Membership.GetUser(existingUser);
memUser.UserName = model.UserName;
Membership.UpdateUser(memUser);

我得到MembershipUser.UserName是只读的。目前已有改变用户名没有其他可用的方法。

I get that MembershipUser.UserName is read only. There are no other available methods for changing the username.

有没有解决这个问题的方法?

Is there a way around this problem?

编辑:新的问题。
当行

New problem. When the line

 var confirmationToken = WebSecurity.CreateUserAndAccount(model.UserName, Request["Password"], new { NameFirst = model.NameFirst, NameLast = model.NameLast, ContactId = newContact.ContactId },true);

运行时,我得到一个MembershipCreateUserException并说用户名已在使用(它实际上不是)。它管理将用户添加到我的UserSecurity表(用户配置),但不将其添加到成员表中。
它试图添加在webpages_Membership表中的用户,而不是我创造了UserMembership表。

is run, I get a MembershipCreateUserException and says the username is already in use (it really isn't). It manages to add the user to my UserSecurity table(UserProfile) but doesn't add it to the membership table. It's attempting to add the user in the webpages_Membership table and not the UserMembership table I created.

推荐答案

您可能无法编辑用户提供的MembershipProvider名称。
在SimpleMembership你有一个用户配置表添加到您的模型,其中的用户名被保存。

You may not be able to edit the users name with the MembershipProvider. In SimpleMembership you have to add a UserProfile table to your Model, where the username is stored.

您在初始化指定表:

WebSecurity.InitializeDatabaseConnection("DBname", "UserProfileTable", "IdColumn", "UsernameColumn", autoCreateTables: true);

这篇关于如何使用mvc4和simplemembership改变用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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