ASP.Net 会员附加字段
我正在启动一个新的 ASP.Net MVC 3 应用程序,我希望能够使用内置的会员提供程序。
我遇到的问题是,我的应用程序可以由各种组织使用,并且显示的信息仅适用于用户所在的组织,这一点很重要。
简单的方法是坚持所有用户都使用他们的电子邮件地址作为用户名,这样每个人都是独一无二的,并且可以与各自的组织相关联。问题是,一些用户没有电子邮件地址,因此没有可靠的方法来确保唯一的名称,我不希望人们知道不同组织已经使用的用户名。 (用户名应该只对组织而言是唯一的,而不是整个应用程序)
理想情况下,我希望用户在一个字段中输入他们的组织名称,然后在另一个字段中输入他们的用户名(然后是密码!)
所以我们可以让 Jane 从一个组织......
Organization Company1
Username Jane
Password ********
然后其他也叫简的人可以从不同的组织登录......
Organization Company2
Username Jane
Password ********
所以我的问题是,修改会员系统以允许这个额外字段的最佳方法是什么?
I am starting a new ASP.Net MVC 3 app and I'm hoping to be able to use the built in Membership provider.
The issue I have is that my application can be used by various organizations and it is important that the information shown is only applicable to the organization the user is working for.
The no brainer approach would be to insist all users use their email addresses as their username so everyone is unique and can be associated with their respective organizations. The problem is, some users don't have email addresses so there is no reliable way of ensuring unique names and I don't want people to know the Usernames already in use by different organizations. (USernames should only be unique to the Organization, not the entire app)
Ideally, I would want the User to enter their organization name in one field, then their username in another (and then the password!)
So we could have Jane login from one organization.....
Organization Company1
Username Jane
Password ********
and then someone else also called Jane could login from a different organization..
Organization Company2
Username Jane
Password ********
So my question is, what is the best way of modifying the Membership system to allow for this extra field?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我会编写一个自定义的 MembershipProvider 来满足要求。
http://msdn.microsoft.com/en-us/library/f1kyba5e.aspx
I'd go about writing a custom MembershipProvider to suite the requirement.
http://msdn.microsoft.com/en-us/library/f1kyba5e.aspx
会员资格使用的提供者模式经过精心设计,以便您可以扩展它。您可以从默认提供程序和默认成员资格使用类继承来添加您需要的字段。这使您不必从头开始编写提供程序。正如@mare 指出的那样,但也存在潜在的陷阱。
我可能会通过一个提示输入组织、用户名和密码的登录表单来克服这些问题。密码,但在幕后结合了 org 和用户名和使用它作为内部用户名。
The provider pattern used by membership is designed so that you can extend it. You can inherit from the default provider and from the default membership use class to add the fields you need. This saves you from having to write a provider from scratch. As @mare pointed out, there are potential pitfalls though.
I would overcome these by perhaps having a login form that prompts for organisation, username & password, but behind the scenes combine the org & username & use that as the internal username.
内置(默认 ASP.NET)成员资格提供程序不提供组织/公司/公司或部门的概念。您将在数据库中为那些具有
aspnet_users
表外键的表创建自己的表,以便能够存储附加信息(我不会更改默认的 aspnet_users 表,因为它可能会使它与当前的默认提供程序或未来的提供程序不兼容)。然后,您需要使用默认提供程序来实现默认功能,并创建一个服务类来支持扩展功能。我知道,我已经做到了。它变得复杂和肮脏,需要时间,但它是完全可行的。您很可能最终会创建自己的提供商,并且从支持公司用户的要求开始。如果您认为更改默认提供程序来支持这一点是没有必要的。关于公司内部独特性的要求是您必须实现的另一项要求。
The built-in (default ASP.NET) membership provider does not provide a concept of an Organization/Company/Firm or Department. You will have create your own tables in the database for those with a foreign key to the
aspnet_users
table to be able to store that additional information (I wouldn't go changing the default aspnet_users table because it might make it incompatible with the current default provider or future ones). You will then need to use the default provider for the default functionality and create a Service class to support the extended functionality. I know, I have done it. It gets complicated and dirty, takes time but it's completely doable.Most likely you will end up creating your own provider and that starts with the requirement to support Users in Companies. In case you thought that changing the default provider to support that wouldn't be necessary. The requirement about uniqueness within the company is another one you will have to implement.
我认为会员资格中有一个内置选项。查看表 my_aspnet_users 中的 APPLICATION 字段。
参考这里:
http://msdn.microsoft.com/en -us/library/system.web.security.membership.applicationname.aspx
I think there is a built in option in the membership. look into the APPLICATION field in table my_aspnet_users.
reference here:
http://msdn.microsoft.com/en-us/library/system.web.security.membership.applicationname.aspx