可选用户管理ASP.NET MVC [英] Alternative User management in ASP.NET MVC

查看:108
本文介绍了可选用户管理ASP.NET MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个新的ASP.NET MVC应用程序和要求的一个存储,是不是在随ASP.NET MVC User类中的标准集的一部分了一些用户信息的计划阶段。我想这可以归结为两个问题。

I am in the planning phase of a new ASP.NET MVC application and one of the requirements is storing some user information that is not part of the standard set found in the User class that comes with ASP.NET MVC. I suppose it comes down to two questions.

1)我可以编辑正在已用于存储,我需要的信息类?

1) Can I edit the class that is being used already to store the information that I need?

2)如果我摇我自己我怎能之类的身份验证一块让事情这么好的试图锁定使用User.IsAuthenticated方法的一些看法时?

2) If I roll my own how can I keep things like the Authentication piece that make things so nice when trying to lock down some views using the User.IsAuthenticated method?

另一种方法我也考虑过使用所提供的用户类的,而是把其他的信息到一个单独的表与GUID的userid外键。

Another alternative I have considered is using the User class provided as is, and instead putting the other information into a separate table with the guid userid as the foreign key.

建议?

推荐答案

配置文件是一个选项作为@Burt说,并提供了很大的灵活性。

Profiles are one option as @Burt says, and offers a lot of flexibility.

我也有类似需要跟踪员工信息,但我选择推出自己的Employee类,并创建一个标准的用户的关系。我很喜欢这是如何制定出我能保持任何员工具体的业务逻辑从<击> User类会员系统是分开的。

I had a similar need to track Employee information, but I opted to roll my own Employee class and create a relationship to a standard User. I really like how this has worked out as I can keep any Employee specific business logic separate from the User class Membership system.

由于并不是每一个用户是要与员工的约束,这使得更多的意义我的情况。它可能不适合你的,但它是一种选择。

Since not every User was going to be bound with an employee, this made more sense for my case. It may not for yours, but it is an alternative.

所以,我有这样的:

public class Employee
{
    public Employee(string name) : this()
    {
        Name = name;
    }

    public virtual string Name { get; set; }
    public virtual string Title { get; set; }
    public virtual decimal Salary { get; set; }
    public virtual decimal Hourly { get; set; }
    public virtual decimal PerDiem { get; set; }
    public virtual string StreetAddress { get; set; }
    public virtual Guid UserId { get; set; }
    public virtual MembershipUser User {
        get
        {
            // note that I don't have a test for null in here, 
            // but should in a real case.
            return Membership.GetUser(UserId);
        }
    }
}

这篇关于可选用户管理ASP.NET MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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