Attila
Attila

Reputation: 712

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.

I just created a simple MVC5 application with Identity 2.0. 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. 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. 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.

Upvotes: 1

Views: 3815

Answers (2)

DSR
DSR

Reputation: 4668

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. Then EntityFramework which is your ORM for asp.net Identity framework will keep database migration track for your 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.

http://msdn.microsoft.com/en-gb/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. But you can use Thinktecture IdentityManager nuget package for this as explained in the following links.

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,

Upvotes: 1

Xavier Egea
Xavier Egea

Reputation: 4763

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.

In this post points that:

The crypto algorithm used in SQL membership is different from the one in the new Identity system. 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.

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. Then when creating an instance UserManager, assign the to the PasswordHasher your new custom password hasher class.

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. There is a users table (AspnetUsers), a roles table (AspnetRoles) and a join table that relates both, the 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.

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.

Upvotes: 0

Related Questions