如何创建ASP.NET身份不同的用户类型? [英] How to create different user types in ASP.NET Identity?

查看:140
本文介绍了如何创建ASP.NET身份不同的用户类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的网络发展。现在我学习ASP.NET MVC 5使用ASP.NET身份。
你能给我一些建议,我的情况:

I'm new to web development. Now I learn ASP.NET MVC 5 with ASP.NET Identity. Can you give me some advices in my situation:

在我的地盘我希望有一些类型的用户。例如:
买方
卖家

In my site I want to have some types of users. For example: Buyer Seller

他们每个人都可以登录并控制他的信息的一部分。(例如,买家可以改变他的信息,添加请求。卖家还可以更改自己的信息,并添加品)

Each of them can login and control his part of information.(e.g. Buyer can change his info, add requests. Seller also can change his own info and add goods)

现在,我创建了这样的事情:

Now, i create something like that:

using Microsoft.AspNet.Identity.EntityFramework;
using System.Data.Entity;

public class ApplicationUser : IdentityUser
{
    public int? BuyerId { get; set; }
    public int? SellerId { get; set; }

    public virtual Buyer Buyer { get; set; }
    public virtual Seller Seller { get; set; }
}

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext()
        : base("DefaultConnection")
    {
    }

    ...

}

当我们创建一个用户,他得到一些角色和财产的信息(例如,如果它的买家,他将有作用买家和一些买方财产(且卖方将是无效)。

When we create a user he get some role and property with information(e.g. if it's buyer he will have role "Buyer" and some Buyer property(and Seller will be null).

这是正常的途径?

更新:

我觉得我挑了一个坏榜样(与卖方和买方)。在我来说,我有这样的事情recomendation系统(另一个例子):

I think I picked a bad example(with Seller and Buyer). In my case I have something like recomendation system(another example):


  1. 用户的头型,谁可以添加信息关于自己和发现一些物品(例如水果)

  2. 用户的第二类,谁添加这个项目(附加信息)(如苹果,梨,葡萄等。其他(第二类型的用户)加入蔬菜)

  3. 最新型的用户,谁可以添加一些额外的信息(如城市)

该系统可附加信息有关用户的基础上,确定该用户的preferences(一些蔬菜或水果)(例如最近的经验等)和物品(例如种类,成本等)

The system can determine the user's preferences (some vegetables or fruit) on the basis of additional information about the user(e.g. recent experience and etc) and items(e.g. kind, cost and etc)

推荐答案

没有。那你想怎么处理这个不是。用户是用户。如果你有能力的真正的区别,你可以使用的角色,但在大多数系统中,如你所描述的东西,是一个买方或卖方是不是一个真正的黑色和白色的东西:那些谁买东西,可最终就好卖,和卖家实际上可能想买的东西。我的建议是没有任何区别的。如果你想只是有一些审批过程或某事某人之前可以卖,那么你就可以再次,只需用卖方的作用,只有那些谁已被添加到该角色会看到卖家的选择。

No. That's not how you want to handle this. Users are users. If you have a true distinction in capabilities, you can use roles, but in most systems like what you're describing, being a "buyer" or a "seller" is not really a black and white thing: those who buy stuff, may eventually like to sell, and sellers may actually want to buy something. My recommendation would be to not make any distinction at all. If you want to just have some approval process or something before someone can sell, then you can, again, just use a "seller" role and only those who have been added to that role will see seller options.

如果你需要存储所独有的作为一个买家或卖家的信息,那么你也可以使用要求,这是灵活得多比增加额外的属性到你的用户模型,绝对更加灵活,创造实际的外键关系存储额外的数据。

If you need to store information that's unique to being a buyer or a seller, then you can also use claims, which are far more flexible than adding additional properties to your user model and definitely far more flexible that creating actual foreign key relationships to store extra data.

这篇关于如何创建ASP.NET身份不同的用户类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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