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

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

问题描述

在一个网站,我需要整合会员和认证。所以,我想用ASP.NET成员的功能,但我有其他自定义的东西,即用户必须做。

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我的自定义用户/客户端对象上的属性?

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).

您更改成员资格提供程序使用自己并使用你的用户对象来存储所有的信息。

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

这一个问题是,它涉及到很多重新执行的东西,已经深受Asp.Net处理的。好事是,你有一个单独的用户对象的所有细节。

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.

通过这种方法,你可以使用原来的成员资格提供程序来处理的用户名和密码,但你有这个的东西,如用户名使用的服务,例如链接自己的用户对象。

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天全站免登陆