use*_*065 9 asp.net-mvc asp.net-identity
有没有人有这个问题.他抛出了我的错误:名称不能为null或为空.但是在表中没有名为"Name"的属性.我想自定义Asp.Net Identity.
调节器
public class HomeController : Controller
{
//
// GET: /Home/
public async Task<ActionResult> Index()
{
var userStore = new UserStore<User,Identity_2Context.MyRole,long,Identity_2Context.MyUserLogin,Identity_2Context.MyUserRole,Identity_2Context.MyClaim>(new Identity_2Context());
var manager = new UserManager<User,long>(userStore);
var user = new User()
{
UserName = "TehnoMac",Email = "TehnoMac@tehcno.com",IsApproved = true,IsLockedOut = false,
CreatedDate = DateTime.Now,LastActivityDate = DateTime.Now,LastLoginDate = DateTime.Now,FailedPasswordAnswerAttemptCount = 0,
FailedPasswordAttemptCount = 0
};
var result = await manager.CreateAsync(user, "test123test");
if (result.Succeeded)
{
var authenticationManager = HttpContext.GetOwinContext().Authentication;
var userIdentity = manager.Create(user, DefaultAuthenticationTypes.ApplicationCookie);
}
else
{
ViewBag.Text = result.Errors.FirstOrDefault();
}
return View();
}
}
Run Code Online (Sandbox Code Playgroud)
IdentityModel公共类ApplicationUser:IdentityUser {}
public class MyClaim:IdentityUserClaim<long>
{
}
public class MyRole:IdentityRole<long,MyUserRole>
{
}
public class MyUserRole:IdentityUserRole<long>
{
}
public class MyUserLogin:IdentityUserLogin<long>
{
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser,MyRole,long,MyUserLogin,MyUserRole,MyClaim>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6564 次 |
| 最近记录: |