Use Database table instead of table created when using Individual Identity Authentication

Asked

Viewed 1,316 times

1

I created an Asp.net MVC application using Identity and left checked the option for Visual Studio to create individual user authentication for me. Turns out I just found out that it creates a . mdf file that contains a database and tables to store user records. I didn’t know this and I ended up creating another table for my system with business rules and etc. When I put the application on the server, logically, this file . mdf with the database and its tables were not and then I could not use authentication. Hence I have so far seen that I have some options:

1 - Create the same tables that exactly match in the BD that I already use in SQL Server and use the "Defaultconnection" connection for the connection I’m using from Entity. For this option, is giving error in my application when trying to create user or log in (since I put users manually in BD):

Detalhes da Exceção: System.InvalidOperationException: The entity type ApplicationUser is not part of the model for the current context.

Erro de Origem: 

Linha 74:             // Isso não conta falhas de login em relação ao bloqueio de conta
Linha 75:             // Para permitir que falhas de senha acionem o bloqueio da conta, altere para shouldLockout: true
Linha 76:             var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
Linha 77:             switch (result)
Linha 78:             {

Arquivo de Origem: c:\Users\sydvagner.franco\Documents\Visual Studio 2013\Projects\LPGPonto\LPGPonto\Controllers\AccountController.cs    Linha: 76 

2 - Try to use both databases for this application. I find it a bit bizarre, but I would accept if it were the simplest. In this case I would migrate the BD to SQL Server (I’ve seen that this is possible, but I haven’t tried yet) or put the file. mdf on the server, changing the Web.config to access that file in the location I put it on the server, rather than in |Datadirectory| as it comes by Default which is the App_data folder of the application (This folder does not appear after the system deploy, so there is no file. mdf automatically created for authentication control).

Functioning of the System

It is an electronic point system that has the tables:

  1. DIARY
  2. HOLIDAY
  3. HOLIDAYS
  4. FUNCTION
  5. OFFICIAL
  6. LOCAL
  7. RECORD (which stores the IP and time of the point record).
  8. Aspnetroles (I took the script and generated the table equal to the one created by Identity)
  9. Aspnetusers (I took the script and generated the table equal to the one created by Identity)

Tables generated in BD automatically to control user authentication

  1. Migrationhistory
  2. Aspnetroles
  3. Aspnetuserslogins
  4. Aspnetuserroles
  5. Aspnetusers

I only put the tables Aspnetusers and Aspnetroles because I thought I will only use these.

  • You can put in your question this definition of your tables so I can get an idea of how this system works?

  • Exactly Tiago Silva. The . mdf file was created before I changed. But I’ve already changed the Connection string to use the same connection created with Entity to access the BD that I created.

  • 1

    In that answer I gave, you did the procedure to generate a Migration and upload your database to an SQL Server?

  • I did not do this yet Gypsy, because I already use a comic, as I said and I did not want to use two comics for the same application. But if you tell me there’s no way, that I have to do this to make it work, I will.

  • @Tiagosilva my Applicationdbcontext looks like this: public Applicationdbcontext() : base("Pontoentities") //: base("Defaultconnection", throwIfV1Schema: false) { } The commented part was the previous connection with Defaultconnection

  • @Sydinhofranco Do when you can. You have no advantage working with . mdf.

  • So OK @Ciganomorrisonmendez I will do this and give a feedback.

  • @Ciganomorrisonmendez I tried to make the migration, but gave this error: "CREATE DATABASE permission denied in database 'master'." My Connection string looks like this: "<add name="Defaultconnection" connectionString="Data Source=LPG-11;Initial Catalog=Lpgponto.Models.Lpgpontocontext;Integrated Security=True;user id=sa;password=123master! @#" providerName="System.Data.Sqlclient" />" Even passing the "sa" user and password SQL Server did not provide access to create the tables?

  • @Ciganomorrisonmendez all right. In your tutorial the "Defaultconnection" was with "Integrated Security=True". I switched to False and it worked. Now I’m using both BD for the same application.

Show 4 more comments

1 answer

1

I did the migration (as shown here) from the database automatically created by Identity to control system user authentication for my SQL Server BD server and now I am using both databases for the same application. It was the way it was given by not having migrated from this bank before and having used this same database for the general data of my application. So, my tip is that whenever someone leaves the option marked for Identity to create user authentication, migrate that database to SQL Server and use that same database to insert other application tables, not need to use 2 database for the same system.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.