gpt4 book ai didi

asp.net-mvc - 名称不能为 null 或为空。 asp.net 身份 mvc 5 + EntityFreamwork

转载 作者:行者123 更新时间:2023-12-02 18:04:24 24 4
gpt4 key购买 nike

有人遇到过这样的问题吗?他向我抛出错误:名称不能为空或为空。但表中没有名为“Name”的属性。我想自定义 Asp.Net Identity。

Controller

  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();
}
}

身份模型公共(public)类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")
{
}
}

最佳答案

确保您已指定用户名。我遇到了同样的错误,设置 UserName 属性后,错误消失了。

关于asp.net-mvc - 名称不能为 null 或为空。 asp.net 身份 mvc 5 + EntityFreamwork,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22129812/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com