如何在我的域模型中实现 ASP.NET 成员资格提供程序 [英] How to implement ASP.NET membership provider in my domain model

查看:21
本文介绍了如何在我的域模型中实现 ASP.NET 成员资格提供程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在网站中,我需要整合会员资格和身份验证.所以我想使用 ASP.NET Membership 的功能,但我有其他自定义的东西,用户"必须做.

In a website, I need to integrate membership and authentication. So I want to use the functionality of ASP.NET Membership, but I have other custom stuff, that a "user" has to do.

所以我坐在这儿拿着我的铅笔和纸,为我的域模型画线......我怎样才能最好地利用 ASP.Net 成员资格,同时扩展它以满足我的需求?

So I am sitting here with my pencil and paper, drawing lines for my domain model... And how can I best utilize the ASP.Net membership, but extend it to fill my needs?

我是否应该创建一个继承自 MembershipUser 的类并使用我自己的属性和方法扩展它(并将其保存在单独的表中).或者我应该让 MembershipUser 成为我的自定义 User/Client 对象的一个​​属性?

Should I create a class that inherits from a MembershipUser and extend it with my own properties and methods (and save this in a seperate table). Or should I let the MembershipUser be a property on my custom User/Client object?

有什么好的方法可以做到这一点?

What would be a good solid way to do this?

推荐答案

我已经考虑过了,有 2 种方法似乎合适(当然还有更多方法可以使它起作用).

I've thought about it and there are 2 ways that seem appropriate (of course there are more ways to make it work).

您将成员资格提供商更改为使用您自己的会员资格提供商,并使用您的 User 对象来存储所有信息.

You change the membership provider to use your own and use your User object to store all the information.

这个的问题在于它涉及到很多已经被 Asp.Net 很好处理的东西的重新实现.好消息是您有一个包含所有详细信息的 User 对象.

The problem with this one is that it involves a lot of re-implementation of things that are already well handled by Asp.Net. The good thing is that you have a single User object with all the details.

使用这种方法,您将使用原始会员资格提供程序来处理用户名和密码,但是您可以通过使用服务将您自己的 User 对象与这个对象链接起来,例如使用用户名之类的东西.

With this method, you would use the original Membership provider to handle the user name and password, but you link your own User object with this one with something like the user name by using a service for example.

设置真的很容易,您只需要创建一个像这样使用的服务:

It's really easy to set up, you just need to create a service that would be used like this:

string userName = "Jon Skeet";
User user = new UserManagementServices().GetUserByUserName(userName);

这篇关于如何在我的域模型中实现 ASP.NET 成员资格提供程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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