0
votes

I've been following this Microsoft Article on implementing a secure web app. It is working fine with the local database. But when I change the connection string to the external database I consistently get an error when trying to interact with the identity tables

  • AspNetUsers
  • AspNetRoles
  • AspNetUserClaims
  • AspNetUserLogins
  • AspNetUserRoles

These tables have been re-created in the external Azure db and I followed this walkthrough. The error I get when trying to register is

The entity type ApplicationUser is not part of the model for the current context.

When trying to register it fails on this line of code in the AccountController

var user = await UserManager.FindByNameAsync(model.Email);

I want to take a database first approach as the external db already has pre-existing data. I've looked at several other posts and sites but I've been unable to solve the issue. I've also tried enabling and updating the db with no success through the Package Manager Console.

Thank you in advance!

Here is the ApplicationDbContext

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

    public static ApplicationDbContext Create()
    {
        //ApplicationDbContext.Equals("", "");
        return new ApplicationDbContext();
    }

    public System.Data.Entity.DbSet<proj.Models.Obj1> Obj3 { get; set; }

    public System.Data.Entity.DbSet<proj.Models.Obj2> Obj3 { get; set; }        

    public System.Data.Entity.DbSet<proj.Models.Obj3> Obj3 { get; set; }
}
1
Can't give you a particular answer base on your description, need more info like code snip , from the error you saw, it might be that your dbcontext need to inherent from ApplicationUser, and also your userManager should hooked up with your new generated dbcontext if your are using Database first approach.LeY
My issue may be in the userManager as I'm unfamiliar with it. I'm coming back to .NET after being away for a few years. What specifically should I be looking for with the userManager?FCoffee
Your UserManager take in a UserStore , and your UserStore have a context setting. msdn.microsoft.com/en-us/library/dn613259(v=vs.108).aspxLeY
I'll go over that info and work on it this evening. I will have to let you know how it goes tomorrow though. I'll be more than happy to award you the answer if I can get it working from your comment. Thank you LeY.FCoffee
Still no luck LeY.FCoffee

1 Answers

1
votes

I don't like answering my own question but here is what resolved my problem.

I had to change the connection string from the one that was generated

<add name="DefaultConnection" connectionString="metadata=res://*/Models.DBName.csdl|res://*/Models.DBName.ssdl|res://*/Models.DBName.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=server;initial catalog=databaseName;user id=username;password=password;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

to this

<add name="DefaultConnection" connectionString="Data Source=server; Initial Catalog=databaseName; User ID=username; Password=password; Connect Timeout=60;" providerName="System.Data.SqlClient" />

I was using the connection string generated during the creation of the EDMX file, database first. Using this connection string was causing my error. I found it a bit deceiving because I was still able to access data from other tables but not the associated identity tables. I hope this will be helpful to anyone experiencing the same issue in the future.