我一直在尝试为用户构建UserController和Views。起初,我在搭建控制器时会收到错误,说:"不支持每个类型有多个对象集。"(这与ApplicationUser和User有关)我正试图将区域/管理中的控制器架起来。
然后我在StackOverflow上发布了一篇帖子,说要将ApplicationUser类重命名为User,这导致了很多错误。我将所有对ApplicationUser的引用都更改为User,但仍然出现相同的错误。我改回ApplicationUser,在Controllers(而不是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
,谁能帮我?
我从EntityModels.cs
中删除了public System.Data.Entity.DbSet<ImpHer.Models.ApplicationUser> ApplicationUsers {get;set;}
。然后在UsersController.cs
中,我将ApplicationUser替换为无处不在的Users。
这就成功了!