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:
- DIARY
- HOLIDAY
- HOLIDAYS
- FUNCTION
- OFFICIAL
- LOCAL
- RECORD (which stores the IP and time of the point record).
- Aspnetroles (I took the script and generated the table equal to the one created by Identity)
- 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
- Migrationhistory
- Aspnetroles
- Aspnetuserslogins
- Aspnetuserroles
- 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?
– Leonel Sanches da Silva
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.
– Sydinho Franco
In that answer I gave, you did the procedure to generate a Migration and upload your database to an SQL Server?
– Leonel Sanches da Silva
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.
– Sydinho Franco
@Tiagosilva my Applicationdbcontext looks like this: public Applicationdbcontext() : base("Pontoentities") //: base("Defaultconnection", throwIfV1Schema: false) { } The commented part was the previous connection with Defaultconnection
– Sydinho Franco
@Sydinhofranco Do when you can. You have no advantage working with . mdf.
– Leonel Sanches da Silva
So OK @Ciganomorrisonmendez I will do this and give a feedback.
– Sydinho Franco
@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?
– Sydinho Franco
@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.
– Sydinho Franco