0

I have the following scenario:

My classic ASP application uses a table called "users" to authenticate our logins. We are moving from ASP to .NET (MVC 5) and we would like to use the new Identity 2.0 framework.

Since almost all our other tables have a foreign key pointing to this table, we are going to initially add/copy users into the two tables until we change all our procedures, views, etc..

Well..To be able to use the User.Identity.GetUserId() method (yes, I already changed from guid to int), I would like to set the Id from new users to be the same as our old table.

Identity Framework automatically sets the Id column to be a sequence and I couldn't find a way to remove this option (but still keeping the PK).

So...should I add a new column "oldid" or is there a way for me to reuse the default column ? Also, if I add this new column, is there a way to override the GeUserId method to return this column instead of the default "Id" ?

Catinodeh
  • 301
  • 3
  • 16
  • This is not what stackoverflow is for. – tdbeckett Aug 18 '15 at 21:14
  • Really @tdbeckett!? I thought it was a place where you can ask something you probably don't know and people who know the answer could post and help you. – Catinodeh Aug 18 '15 at 21:25
  • How are the users being copied? If it's via, say, an SQL script (external to the application) then you can use IDENTITY INSERT to override the the identity column. See https://msdn.microsoft.com/en-us/library/ms188059.aspx – Brendan Green Aug 18 '15 at 21:49
  • They are being copied as they log in @BrendanGreen. We validate if the user exists in our old "dbo.users" table and if it does we create the user using the Register method. That's where I can't find a way to create the new AspnetUser using the old primary key. – Catinodeh Aug 18 '15 at 21:52
  • You may have to bypass the Asp.Net Identity libraries to do this. Alternatively, you could extend `IdentityUser` to include a unique field that contains the old UserId, and have your other tables link to that instead. – Brendan Green Aug 18 '15 at 21:59
  • I know I can do this @BrendanGreen, but how can I get this info on every request without having to query the database? – Catinodeh Aug 18 '15 at 22:00
  • See my answer here: http://stackoverflow.com/questions/31974228/can-you-extend-httpcontext-current-user-identity-properties/31976327#31976327 During logon, add a claim containing the old UserId. No need to hit the database at all post logon. – Brendan Green Aug 18 '15 at 22:08

0 Answers0