ASP.NET成员资格和EF [英] ASP.NET Membership and EF
问题描述
我有一个名为网站
,可能有许多用户表。 (网站和用户之间的许多-2多关系)。不过,我使用ASP.NET内置成员API和Entity Framework来处理数据。
I have a table called Websites
that could have many users. (Many-2-Many relationship between Websites and Users). However, I am using ASP.NET Built-in Membership API and Entity Framework to handle data.
我想什么做的,是将用户添加到使用EF因为这样的网站对象:website.Users.Add(对象的MembershipUser这里)。
就这么简单,如果不是会员API它会一直要容易得多。但是,当创建一个新用户,我想从一个复选框列表分配访问来自网站表特定的网站。
What I would like to do, is to add a User to a Website object using EF as such: website.Users.Add(MembershipUser object here). Simple as that, if this wasn't the Membership API it would've been much easier. But When creating a new user i'd like to assign access to specific websites from the websites table from a checkbox list.
我怎样才能做到这一点?
How can I do this?
感谢
推荐答案
您的问题是很多更复杂,你可能无法得到所有的答案在一个单一的问题。我会尽力的。
You question is a lot more complex, and you might not be able to get all answers in a single question. I'll try my best.
下面是我的做法 -
Here is my approach -
1)使用新的<一个href=\"http://www.hanselman.com/blog/IntroducingSystemWebProvidersASPNETUniversalProvidersForSessionMembershipRolesAndUserProfileOnSQLCompactAndSQLAzure.aspx\"相对=nofollow> ASP.Net通用提供商
2)实施定义成员资格提供并重写
public override bool ValidateUser(string username, string password)
所以,你可以验证用户对用户表格以及网站表。
3)创建自己注册,而不是使用的CreateUserWizard的。例如,使用常规的文本框。
3) Create registration yourself instead of using CreateUserWizard. For example, using regular textboxes.
MembershipCreateStatus status;
MembershipUser membershipUser = System.Web.Security.Membership.CreateUser(
UsernameTextBox.Text, PasswordTextBox.Text, EmailTextBox.Text,
PasswordQuestioTextBox.Text, PasswordAnswerTextBox.Text, true, out status);
// Then assign user to website based on the selected checkboxes
数据库关系
这篇关于ASP.NET成员资格和EF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!