实体类型ApplicationUser不是当前上下文Asp.Net MVC的模型的一部分

以下是我的申请所需的代码。 我在我的帐户控制器文件中收到上述错误。 我在MVC 4中使用内置的帐户注册和登录代码。 无法注册用户。 我在stackoverflow上看到下面的链接解决我的错误但无法解决它

链接我跟着

我的Web中的连接字符串。配置代码

    

IdentityModel.cs文件

 using System.Data.Entity; using System.Security.Claims; using System.Threading.Tasks; using Microsoft.AspNet.Identity; using Microsoft.AspNet.Identity.EntityFramework; namespace PromoteMyName.Models { // You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more. public class ApplicationUser : IdentityUser { public async Task GenerateUserIdentityAsync(UserManager manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Add custom user claims here return userIdentity; } } public class ApplicationDbContext : IdentityDbContext { public ApplicationDbContext() : base("DefaultConnection", throwIfV1Schema: false) { } public static ApplicationDbContext Create() { return new ApplicationDbContext(); } } } 

我的DbContent文件

 public partial class PromoteMyNameEntities1 : DbContext { public PromoteMyNameEntities1() : base("name=PromoteMyNameEntities1") { } 

AccountController.CS(在此文件中出错)

  // POST: /Account/Register [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; //Getting Error at Line Below var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking here"); return RedirectToAction("BusinessCategory", "ClientBusinesses"); } AddErrors(result); } // If we got this far, something failed, redisplay form return View(model); } 

第1点:我在你的web.config中看到你有两个连接字符串,但两个都使用相同的连接和相同的数据库,所以你不需要第二个。 从web.config中删除以下行

  

第2点:我认为你已经为内置成员Db Sure Short解决方案做了一些麻烦问题是去你的数据库删除Aspnet / Inbuilt表(我的意思是删除由代码第一个成员资格创建的db中的表)

删除这些表后。 现在清理解决方案,然后重新构建解决方案,然后运行解决方案它将自动在数据库中创建新的memebership表。