【问题标题】:Extending aspnet_users to add additional field扩展 aspnet_users 以添加附加字段
【发布时间】:2013-12-11 19:48:29
【问题描述】:

我在lightswitch 中构建了一个应用程序,并为它们创建了用户角色和身份验证。在我的数据库中,我有所有aspnet security 表。现在在aspnet_Users 我有我的所有用户和aspnet_memebership 有相关信息。我需要在任一表(你们推荐的)中添加一个字段来捕获附加信息,即国家。我的意图是在 asp.net 应用程序中使用我的代码时,我可以为用户获取国家/地区。类似于我如何使用以下代码获取用户的身份名称。

已编辑 我知道如何在表中添加字段,我不知道如何使用 User.Identity 访问该字段...我希望我的新字段显示在代码中。

如果有什么误会请见谅。

Application.Current.User.Identity.Name;

我想为个人国家实现类似的目标,例如:

Application.Current.User.Identity.Country

【问题讨论】:

  • 您是在问如何将此列添加到表中,还是在问哪个表最适合将此列添加到?
  • 我对此知之甚少,无法发布答案,但我 99% 确定 Application.Current.User.Identity.Country 将不起作用,因为它不作为对象存在( User.Identity.Country 是在其中一个系统程序集中找到的预构建对象)。因此,您将必须创建此对象以及它用于连接数据库和检索所需数据的方法。查看这些链接:msdn.microsoft.com/en-us/library/bb386940(v=vs.110).aspxstackoverflow.com/questions/4002323/…

标签: asp.net security .net-security


【解决方案1】:

听起来您需要实现 Custom Membership UserCustom Membership Provider 才能访问其他属性。

然后您需要使用MembershipProvider.GetUser().Country 来检索该属性(其中MembershipProvider 是您的会员提供者的名称)。

如果您确实想访问Application.Current.User.Identity.Country,那么您可以创建自己的继承自System.Security.Principal.IIdentity 的类,然后在访问该属性之前将Application.Current.User.Identity 转换为您自己的类型。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-15
    相关资源
    最近更新 更多