0

I'm looking for advice here. I have Identity 2 set up on my application. In Dev we use Entity Framework but in our test environment we update the database using SQL scripts, due to DBA policies.

I need to initially seed an Admin user the first time the application runs so that they can then add new users. Access to the app needs to be controlled. In Dev we use the seed method.

For our test environment I need to be able to seed the users, but because the password is saved to the database in an encrypted format, I'm not too sure how to handle this. From what I understand is that Identity 2 generates a seed every time the application runs for the first time and this seed is used to encrypt passwords.

Has anyone got a good solution for this?

LeftyX
  • 35,328
  • 21
  • 132
  • 193
Jeff Finn
  • 1,975
  • 6
  • 23
  • 52

1 Answers1

1

have you considered using the Application_Start method of Global.asax.cs? You can create a method of your own and call it on the Application_Start() to check if there is a certain user in the database, if not, create the role and user you want.

C-JARP
  • 1,028
  • 14
  • 16
  • Ye I had tried that and it worked. I'm not sure I'm overly happy with it as a solution though. It seems like a hack to me, I could be wrong tho if it is considered best / good practice than I'll be happy with it. – Jeff Finn Apr 08 '15 at 14:30
  • The good practice would be to use the seed methods, onmodelcreate, onmodelchange, etc, but since you have some policies that you have to respect, that is the only way that comes to mind. – C-JARP Apr 08 '15 at 14:48