没有 MembershipUser 的自定义 MembershipProvider
是否可以在不使用 MembershipUser 类的情况下创建自定义 MembershipProvider ?
我想使用我自己的 User 类并保持整洁,我不想使用 MembershipUser 类,它有很多我真的不想要或不需要的属性。
Is it possible to create a custom MembershipProvider without the use of the MembershipUser class?
I'd like to use my own User class and to keep things tidy, I'd like to not have to use the MembershipUser class which has a lot of properties I really don't want or need.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不,不是。但您始终可以使用
Repository
模式或类似模式在其之上编写自己的抽象,然后在应用程序中使用您自己的User
模型。No it's not. But you can always write your own abstraction on top of it using a
Repository
pattern or similar, and then use your ownUser
model in the application.如果您确实想在 ASP.NET 会员基础设施中内置您的提供程序,那么您应该这样做。
Membership.Provider 返回抽象 MembershipProvider 还包含:
以及返回 MembershipUser 类。
If you really want to build-in your provider in ASP.NET Membership infrastructure, you should.
Membership.Provider returns abstract MembershipProvider also containing:
and other methods returning MembershipUser class.
您可以创建自定义会员资格提供程序,而无需根据您的使用情况使用/继承会员用户。如果您没有使用内置的 createuser 方法(用户是在另一个源系统中创建的),那么您确实不需要成员资格用户对象。否则,只需创建另一个使用您的额外属性从membershipuser 继承的对象。
You can create a custom memembership provider without using/inheriting from the membership user depending upon your usage. If you are not using the built in createuser method (the user is created in another source system), then you really don't need the membership user object. Otherwise, just create another object that inherits from membershipuser with your extra properties.
这是我的解决方案
customerUser.cs
customerProvider.cs
当该方法需要返回 MembershipUser 类型时,请使用客户用户的信息构建一个新类型。大多数情况下,都会好的。因为内置控件(登录,登录状态。)不需要更多。但我建议通过继承 MembershipUser 来自定义您自己的用户,附加属性不会让您烦恼,但缺乏会。
this is my solution
customerUser.cs
customerProvider.cs
when the method need returning a MembershipUser type, build a new one with your customer user's infomation . in most case, it will be fine. because the build-in Controls(login, loginstatus.) doesn't need more than those. but i sugguest custom your ownuser by inheriting the MembershipUser,the additional properties will not bite you ,but the lackness will.