IdentityModels.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System.Data.Entity;
  2. using System.Security.Claims;
  3. using System.Threading.Tasks;
  4. using Microsoft.AspNet.Identity;
  5. using Microsoft.AspNet.Identity.EntityFramework;
  6. namespace Winsoft.GOV.XF.WX.Models
  7. {
  8. // You can add profile data for the user by adding more properties to your ApplicationUser class, please visit https://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
  9. public class ApplicationUser : IdentityUser
  10. {
  11. public string Hometown { get; set; }
  12. public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
  13. {
  14. // 请注意,authenticationType 必须与 CookieAuthenticationOptions.AuthenticationType 中定义的相应项匹配
  15. var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
  16. // 在此处添加自定义用户声明
  17. return userIdentity;
  18. }
  19. }
  20. public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
  21. {
  22. public ApplicationDbContext()
  23. : base("DefaultConnection", throwIfV1Schema: false)
  24. {
  25. }
  26. public static ApplicationDbContext Create()
  27. {
  28. return new ApplicationDbContext();
  29. }
  30. }
  31. }