小编jou*_*jou的帖子

User.Identity.GetUserId() 返回 null

当我使用User.Identity.GetUserId()方法时,它返回 null。我正在尝试创建一种方法(基于AccountControllerMVC)来更改用户的密码。问题在于User.Identity.GetUserId()返回 null。

看看我的控制器,如果可以的话请帮忙。

开始和构造函数

protected ApplicationDbContext ApplicationDbContext { get; set; }
    protected UserManager<ApplicationUser> UserManager { get; set; }

    public ClienteController()
    {
        this.ApplicationDbContext = new ApplicationDbContext();
        this.UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(this.ApplicationDbContext));
        //this.UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db));
    }
Run Code Online (Sandbox Code Playgroud)

登录方式

[HttpPost]
    [AllowAnonymous]
    public ActionResult Login(ClienteViewModel model, string returnUrl)
    {
        Cliente cliente = ChecarAcesso(model);

        if (cliente != null)
        {
            var claims = new List<Claim>();
            claims.Add(new Claim(ClaimTypes.Name, cliente.nomeCompletoCliente));
            claims.Add(new Claim(ClaimTypes.Email, cliente.emailCliente));

            var id = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);

            var …
Run Code Online (Sandbox Code Playgroud)

c# asp.net authentication asp.net-mvc

5
推荐指数
1
解决办法
5383
查看次数

标签 统计

asp.net ×1

asp.net-mvc ×1

authentication ×1

c# ×1