简体   繁体   中英

How to create users from old asp.net membership to new MVC .net and send password reset

sorry if this sounds noob--I am a hobbyist: I have an older asp.net (vb) forms membership on an azure sql DB that was made with code first option in visual studio 2012 template (Entity version 6 if that helps). I wanted to transition to MVC . The template for ac# MVC project worked awesome with azure, and I got the open auth working, but I have no idea how I could get my old users into the new membership. The DB fields look quite different (the MCV only has a few tables and seems far more straight forward, whereas the older asp.net from VS2012 has multiple tables, password salts, etc. I have about 500 users, so doing manually sounds terrible. I tried copying over a test user's email and then trying to reset the password--it send as password reset email, but then gives an "error occurred" on when it arrives at the password reset view, guessing because the user was never problematically set up. So, is there a methods for transitioning to a new membership system? I could probably figure out how to run some script for creating a bunch of users from an email list, but how could I have each user emailed a reset link at the same time. Any guidance here would help, thanks

What I'd do is create new users in the MVC site using the emails of the old users. You can do that a number of ways, either write some quick DB code to read the email addresses, export to a text file and read the text file, or just hard code an array with all the address.

Then use a loop to add each as a new user, so you get them in the system correctly, then run a password reset on each new account so the user can just set a new password.

Something like this:

//loop for each email address from old DB

var user = new ApplicationUser { UserName = _email, Email = _email };
var result = await UserManager.CreateAsync(user, "TempPass123!");
if (result.Succeeded)
{
 //reset the password
}

Take a peek at this article for some guidance: Create a secure ASP.NET MVC 5 web app with log in, email confirmation and password reset

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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