简体   繁体   English

MVC5 ASP.net Identity 2.0用户管理以及从localDB部署到IIS服务器8

[英]MVC5 ASP.net Identity 2.0 user management and deploy from localDB to IIS server 8

I am new to ASP.net MVC5 and Identity, after having used WebForms and the Membership provider for almost one year. 在使用WebForms和成员资格提供程序将近一年之后,我是ASP.net MVC5和Identity的新手。

I just created a simple MVC5 application with Identity 2.0. 我刚刚使用Identity 2.0创建了一个简单的MVC5应用程序。 A admin user can login and upload new documents and add new links. 管理员用户可以登录并上传新文档并添加新链接。 I disabled user registration (After having registered the first admin user) as I will need to create admin users manually. 我禁用了用户注册(在注册了第一个管理员用户之后),因为我将需要手动创建管理员用户。

I deployed the project to an IIS 8 server, and it works fine, I exported the asp.net Identity tables from my localDB using SQL Management Studio and imported them in the same SQL database as the project is using, changing the web.config connection string that is used locally pointing to the mdf file in App_Data, to point to the SQL database where I imported the Identity Tables. 我将项目部署到IIS 8服务器上,并且工作正常,我使用SQL Management Studio从localDB导出了asp.net Identity表,并将它们导入与项目使用的相同SQL数据库中,从而更改了web.config连接本地使用的字符串,指向App_Data中的mdf文件,以指向导入身份表的SQL数据库。 Unfortunately this attempt did not work, as using the same login credentials generates a login fail. 不幸的是,此尝试不起作用,因为使用相同的登录凭据会导致登录失败。

First question: Was this the best approach to integrate the identity tables into my project database? 第一个问题:这是将身份表集成到我的项目数据库中的最佳方法吗? If not, what else should I do? 如果没有,我该怎么办?

Second question: When I was using the Membership provider I managed users from the IIS Users and roles tools. 第二个问题:使用成员资格提供程序时,我通过IIS用户和角色工具管理用户。 Now I am not aware of any systems to manage users and roles. 现在,我不知道有任何系统可以管理用户和角色。 How can I create new users without using the registration form? 在不使用注册表格的情况下如何创建新用户? How can I manage these users and roles? 如何管理这些用户和角色?

Many thanks in advance. 提前谢谢了。

Answer to first question 回答第一个问题

The issue is, initially you have used code first approach which is default when you create register the first admin user, that will automatically creates all required tables in localDB in App_Data folder. 问题是,最初您使用的是代码优先方法,该方法在创建时注册第一位管理员用户时默认使用,这将在App_Data文件夹的localDB中自动创建所有必需的表。 Then EntityFramework which is your ORM for asp.net Identity framework will keep database migration track for your localDB. 然后,作为您的asp.net身份框架的ORM的EntityFramework将为您的localDB跟踪数据库迁移。

Once you have change the database connection you need to use code first database migration to update your code and database. 更改数据库连接后,需要使用代码优先数据库迁移来更新代码和数据库。 (If you haven't changed the table names) (如果您尚未更改表名)

Use following links to get some idea about migrations and you can use Package Manager Console to do that using "Update-Database" command. 使用以下链接可以了解有关迁移的信息,并且可以使用“程序包管理器控制台”通过“ Update-Database”命令来执行此操作。

http://msdn.microsoft.com/en-gb/data/jj591621.aspx http://www.dotnet-tricks.com/Tutorial/entityframework/R54K181213-Understanding-Entity-Framework-Code-First-Migrations.html http://msdn.microsoft.com/zh-CN/data/jj591621.aspx http://www.dotnet-tricks.com/Tutorial/entityframework/R54K181213-Understanding-Entity-Framework-Code-First-Migrations.html

Second question 第二个问题

There isn't any Microsoft out of the box solution for managing user for Identity Framework. 没有任何用于管理Identity Framework用户的Microsoft即用型解决方案。 But you can use Thinktecture IdentityManager nuget package for this as explained in the following links. 但是您可以为此使用Thinktecture IdentityManager nuget软件包,如以下链接中所述。

http://brockallen.com/2014/04/09/introducing-thinktecture-identitymanager/ http://www.hanselman.com/blog/ThinktectureIdentityManagerAsAReplacementForTheASPNETWebSiteAdministrationTool.aspx http://brockallen.com/2014/04/09/introducing-thinktecture-identitymanager/ http://www.hanselman.com/blog/ThinktectureIdentityManagerAsAReplacementForTheASPNETWebSiteAdministrationTool.aspx

Let me know if you have any further issues. 让我知道您是否还有其他问题。

Hope this helps, 希望这可以帮助,

I've reviewed the next link about Migrating exiting Website from Sql Membership to Asp.net Identity , that I think can be useful for you. 我已经查看了有关将退出网站从Sql成员身份迁移到Asp.net Identity的下一个链接,我认为这对您有用。

In this post points that: 在这篇文章中指出:

The crypto algorithm used in SQL membership is different from the one in the new Identity system . SQL成员资格中使用加密算法不同于新Identity系统中加密算法 To reuse old passwords we need to selectively decrypt passwords when old users log in using the SQL memberships algorithm while using the crypto algorithm in Identity for the new users. 要重用旧密码,我们需要在旧用户使用SQL成员资格算法登录时有选择地对密码进行解密,而新用户使用Identity中的加密算法。

So, this should be the main problem login problem that you have. 因此,这应该是您遇到的主要登录问题。 Despite what article says, in Asp.net identity you can define your custom password hasher, so can use the Membership algorithm to login with Asp.Net Identity, just creating a custom password hasher that implements IPasswordHasher. 不管文章怎么说,在Asp.net身份中您都可以定义自定义密码哈希器,因此可以使用Membership算法登录Asp.Net身份,只需创建实现IPasswordHasher的自定义密码哈希器即可。 Then when creating an instance UserManager, assign the to the PasswordHasher your new custom password hasher class. 然后,在创建实例UserManager时,将新的自定义密码哈希器类分配给PasswordHasher。

UserManager<ApplicationUser> UserManager = new UserManager<ApplicationUser>(store);
UserManager.PasswordHasher = new CustomPasswordHasher(); // IPasswordHasher

For the second question, the users and roles management in Asp.net Identity has no secret. 对于第二个问题,Asp.net Identity中的用户和角色管理不是秘密。 There is a users table (AspnetUsers), a roles table (AspnetRoles) and a join table that relates both, the AspnetUserRoles. 有一个用户表(AspnetUsers),一个角色表(AspnetRoles)和一个联接表,两者关联了AspnetUserRoles。 So, for migration your users from the old database you can do it inserting users, roles and their relation in these tables using SQL Scripts. 因此,为了从旧数据库迁移用户,您可以使用SQL脚本在这些表中插入用户,角色及其关系。

However, check the step by step tutorial I suggested, that I'm sure will avoid some other problems that you could have in this migration process. 但是,请查看我建议的分步教程,我肯定会避免在此迁移过程中可能遇到的其他问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM