Reputation: 168
I'm looking for some guidance here... I have an old ASP.NET webforms site with an existing database and SQL Server membership, and I'm creating a new interface using ASP.NET MVC and Entity Framework with a database-first approach.
So I have tables as shown below:
My problem is, I'm unsure how to make use of these old membership tables for authentication in the new ASP.NET MVC application.
I don't mind whether I migrate the user/roles data to ASP.NET Identity or continue using the old membership database but I'm not sure what the best approach is. I think I would prefer to migrate the data, as I am more familiar with Identity.
What I've tried...
While searching for solutions I have come across this: Migrating an Existing Website from SQL Membership to ASP.NET Identity several times, however this (and most of what I've found so far) is talking about upgrading an existing webforms site to use asp.net identity. I have tried using parts of it to migrate the Membership data to asp.net identity, but of course the remaining instructions don't fit my scenario.
So here's where I'm at now.
I have used the SQL script in the walkthrough linked above to migrate membership data to asp.net identity tables.
I have set up SQLPasswordHasher as described in the walkthrough, since I figure I'll need that function to use existing logins.
I imported those tables to the database that contains the website data, in hopes that I'd only have to deal with a single connection string.
I modified ApplicationDbContext : base
... to use that database (it was previously using DefaultConnection (LocalDb)
So now I have these tables populated with data:
Aaand I'm stuck.
It's entirely possible that I'm missing something basic, but anyway if I try to login or register a new user in it's current state I get the error:
The entity type ApplicationUser is not part of the model for the current context.
on the line:
var result = await UserManager.CreateAsync(user, model.Password);`
The only solutions I've been able to find for that error have been on code-first projects: something to do with migrations, which I'm not using (I did try it but received an error on enable-migration "Creating a DbModelBuilder or writing the EDMX from a DbContext
created using database-first or model-first is not supported.")
UPDATE
Ok so I came across an answer regarding the The entity type ApplicationUser is not part of the model for the current context.
error, apparently using the connection string generated by entity framework can be problematic, so as advised, I made a 'normal' connection string and this seems to be getting closer!
UPDATE 2
I think I have it working, will run some tests though before updating with my solution.
Upvotes: 0
Views: 865
Reputation: 296
Please follow the below step to do this.
Hope this will help you !
Upvotes: 1