我一直在尝试为用户构建UserController和Views。首先,当脚手架控制器说:"不支持每种类型的多个对象集时,我会收到错误。" (这与ApplicationUser和User有关) 我正在尝试在Areas / Admin中构建控制器。
然后我在StackOverflow上发帖说要将ApplicationUser类重命名为User,这导致了很多错误。我将所有对ApplicationUser的引用更改为User,但我仍然遇到了同样的错误。 我改回了ApplicationUser,再次在控制器(而不是在Areas / Admin中)尝试将其替换为脚手架。这似乎有效,直到我运行应用程序。它给了我完全相同的错误。
using System.Data.Entity;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
namespace ImpHer.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 string PostalCode { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> 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<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
public System.Data.Entity.DbSet<ImpHer.Models.Project> Projects { get; set; }
public System.Data.Entity.DbSet<ImpHer.Models.Category> Categories { get; set; }
public System.Data.Entity.DbSet<ImpHer.Models.ApplicationUser> ApplicationUsers { get; set; }
}
}
这是IdentityModels.cs
谁可以帮助我?
答案 0 :(得分:1)
我从public System.Data.Entity.DbSet<ImpHer.Models.ApplicationUser> ApplicationUsers {get;set;}
删除了EntityModels.cs
。
然后在UsersController.cs
中,我将ApplicationUser替换为各地的用户。
这就是诀窍!