如何使用 MVC5RC/RTW 对现有数据库进行身份验证 [英] How to Authenticate using MVC5RC/RTW with existing database

本文介绍了如何使用 MVC5RC/RTW 对现有数据库进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最初在 Identity 中问这个问题测试版.从那时起,类和接口发生了很大变化,并且 出现 RTW 版本在 RC 上再次进行了一些修改版本.原则上我需要实现以下目标.

I originally asked this question when Identity was in beta. The classes and interfaces have changed considerably since then and it appears the RTW version has some modifications again over the RC version. In principle I need to achieve the following.

  • 根据我的用户表 tblMembers 验证本地登录,其中包含用户 ID 字段和密码,这是我需要验证的两个项目.
  • 可以通过 Controller.User 属性访问我的 tblMember 记录/类(在 MVC5 身份之前,我已经使用 membership provider 方法.)无论用户是否登录通过 localuser 方法或通过其他 OAuth 提供商之一(Twitter、Google 等).
  • 能够显示我自己的自定义用户名,尽管使用登录方法.本地用户使用用户 ID 1234567 和密码登录,理想情况下,无论身份验证方法如何(本地/Twitter 等),我都希望显示John Smith (1234567)"
  • authenticate the local login against my usertable tblMembers which contains the userid field and password which are the two items I need to authenticate.
  • have access to my tblMember record/class via the Controller.User property (Prior to MVC5 identity I had achieved this using the membership provider methods.) regardless of if the user logged in via the localuser method or via one of the other OAuth providers (Twitter, Google etc).
  • Ability to display my own custom username despite the login method. Local users login with a userid 1234567 and a password, ideally I would like to display "John Smith (1234567)" regardless of the authentication method (local/Twitter etc)

一开始我不确定我的成员类应该继承什么aspIdentitySample 项目,我应该使用 IdentityUser 吗?

Initially I'm unsure as to what my memberclass should be inheriting from It appears from the aspIdentitySample project that I should be using IdentityUser?

        public partial class tblMember
        {
            public int id { get; set; }
            public string membership_id { get; set; }
            public string password { get; set; }
            ....other fields
        }

是否有将现有数据库/用户表与 ASP.NET Identity 系统集成的新示例或更新示例?

Are there any new or updated examples of integrating your existing database/user tables with the ASP.NET Identity system?

推荐答案

我还将身份表添加到我的数据库中.如果您在 Visual Studio 2013 中创建一个新的 Web 项目,您将看到现在在 RTM 中一切都比 RC 更好,而且您将看到下表

I am also adding the identity tables to my database. If you create a new web project in visual studio 2013 you will see that now in RTM everything works better than RC plus you will see the following table

  public class ApplicationUser : IdentityUser
  {


   }

因此您可以调用表 tblMembers 而不是 ApplicationUser

So Instead of ApplicationUser you can call your table tblMembers

  public class tblMembers : IdentityUser
  {


   }

您的表 tblMembers 将继承 Id Username Password 安全标记和一个说明这是 tblMemeber 的鉴别器列

your table tblMembers will inherit Id Username Password security stamp and a discriminator column saying this is a tblMemeber

不为身份验证创建自定义类,最简单的方法就是将用户名设为旧用户名和用户 ID 的组合.然后将用户的真实姓名或旧用户名存储在单独的列中.

without making custom classes for authentication the easiest thing to do would be just to make the username the combination of your old usernames and userids. Then store the users real name or old username without the user id in a separate column.

让用户使用内置用户登录进行注册,他们可以进入管理帐户并点击使用其他服务登录.这会将谷歌帐户链接到他们的常规帐户,因此无论他们使用哪个都会登录他们在同一个帐户.如果您有具有连接表信息的用户,我建议您使用与模板中的注册方法类似的内容为所有用户播种您的表.然后只需将新的组合用户名和 Id 与旧的相匹配,并在需要的地方填充数据sql管理工作室.

have the users register with the built in user login and they can go to manage account and click use another service to log in. This will link the Google account to their regular account, so no matter which one they use it will log them in to the same account. If you have users with connected table information, I suggest you seed your table with all the users with something similar to the register method found in the template.Then just match the new combined username and Id to the old ones and populate data where needed in sql management studio.

再次修复了 RC 中扩展 IdentityUsers 的许多问题.Microsoft 已经在身份用户存储和本教程中添加了更多功能 http://www.windowsazure.com/en-us/develop/net/tutorials/web-site-with-sql-database/ 应该很快就会更新.我计划在我更改完数据库后自己走一遍,但现在我希望我的建议是比您可能想要实施的更简单的解决方案.

Again a lot of issues in RC with extending IdentityUsers have been fixed. Microsoft is already adding more features to the identity user store and this tutorial http://www.windowsazure.com/en-us/develop/net/tutorials/web-site-with-sql-database/ is supposed to be updated soon. I plan on making my own walk through when i'm done changing my database but for now I hope my suggestions even though they are a simpler solution than you might want to implement.

这篇关于如何使用 MVC5RC/RTW 对现有数据库进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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