0

I using C# Identity for login/registering users. Everything works locally but when I publish live the register/login doesn't work. I believe it is due to the connection string because it is pointing to LocalDb. I've been trying to put it in my server database, but when I do, I get ApplicationUser not part of model. I'm only using the AspNetUser table for now. Any suggestions?

Default connection string

<add name="DefaultConnection" 
     connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-WebApplication1-20171104124939.mdf;Initial Catalog=aspnet-WebApplication1-20171104124939;Integrated Security=True" 
     providerName="System.Data.SqlClient"/>

Server connection string -- I'm using gearhost as my server provider.

<add name="connectionStringName" 
     connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=den1.mssql1.gear.host;initial catalog=databaseName;user id=userName;password=userPassword;MultipleActiveResultSets=True;App=EntityFramework&quot;" 
     providerName="System.Data.EntityClient" />

This is the DefaultConnection database context.. if I change this to my server connection string with copied identity tables, it gives me the "500, ApplicationUser not part of model"

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext()
        : base("DefaultConnection", throwIfV1Schema: false)
    {
    }

    public static ApplicationDbContext Create()
    {
        return new ApplicationDbContext();
    }
}
6
  • Why does your Server Connection string use EF Models? Commented Mar 23, 2018 at 20:33
  • @ErikPhilips I'm not sure I understand your question.. but the connection string was generated like that because I used EF Designer from database using Visual Studio 2015 Entity Data Model Wizard Commented Mar 23, 2018 at 20:36
  • Your question is very unclear. Are both those connection strings in your web.config or only 1? Because one is a normal connection string and the other is an EF connection, and they are NOT compatible to just switch. Commented Mar 23, 2018 at 20:55
  • Those are both connection strings in my web.config Commented Mar 23, 2018 at 21:00
  • You will probably need both connection strings, one for identity and the other for EF model. They can point to the same database. Commented Mar 23, 2018 at 21:22

2 Answers 2

1

Found exacly what I was looking for in this video..

https://www.youtube.com/watch?v=Y02ccL4-_K4

I basically needed to change the default connection string created by ASP.net to be pointed in my own database. Also, I needed to know how to create the identity tables in my database. The video shows me how to do these.

Sign up to request clarification or add additional context in comments.

Comments

0

Perhaps I don't understand well what you need, but usually identity tables should be in the same database as your other tables, related to your specific problem. Perhaps you also want some relationships between users/identities and your 'business' tables.

If that's the case, you can change your default connection string to point to the same database as your EF connection string. This will make your identity make the necessary tables in your EF database, and after that you can just import these tables in your edmx.

This will make your EF model have the same entities as your identity model.

Hope this helps, Tom

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.