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

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

问题描述

我最初问这个<一个href=\"http://stackoverflow.com/questions/17641956/howto-use-new-mvc5-authentication-with-existing-database\">question当身份是处于测试阶段。的类和接口从那时起已经发生很大变化,它出现 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.


  • 验证本地登录对我的包含用户标识字段和密码为UserTable tblMembers这是两个项目,我需要进行身份验证。

  • 必须通过Controller.User属性访问我的tblMember记录/班(在此之前MVC5身份我已经实现这个使用成员提供方法。)不管用户通过为localuser方法或通过其他OAuth的供应商之一特(Twitter,谷歌等)登录的。

  • 能力尽管登录方法,以显示自己的自定义用户名。本地用户登录与用户ID 1234567和密码,最好我想显示约翰·史密斯(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识别系统集成现有的数据库/用户表中的任何新的或更新的例子吗?

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

推荐答案

我也在标识表到我的数据库。如果您在Visual Studio中新的Web项目2013你会看到,现在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
  {


   }

所以不是ApplicationUser,你可以打电话给你的表tblMembers

So Instead of ApplicationUser you can call your table tblMembers

  public class tblMembers : IdentityUser
  {


   }

你的表tblMembers将继承标识用户名密码的安全性邮票和鉴别列说这是一个tblMemeber

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

未做自定义类进行身份验证的最简单的事情是只是为了让你的用户名老用户名和用户ID的组合。然后,存储用户的真实姓名或用户名老人没有在一个单独的列中的用户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.

有用户注册内置的用户登录,他们可以去管理账户,点击使用其他服务来登录。这将谷歌帐户链接到他们的定期账户,所以无论他们使用哪一个会记录他们以相同的帐户。如果你有连接的表信息的用户,我建议你用的种子全部用类似于template.Then发现register方法​​的一些用户在你的桌子刚好符合新合并的用户名和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已得到修复。微软已经加入更多功能给用户身份的存储和本教程的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天全站免登陆