Use Username instead of Email for identity in Asp.net mvc5

前端 未结 4 1255
南旧
南旧 2020-12-02 15:49

Whenever I create a new application with visual studio 2013 express for web and using the individual accounts authentication and i hit the register button I notice that it i

4条回答
  •  萌比男神i
    2020-12-02 16:08

    You can also use username and/or password like this

    var user = await _userManager.Users
           .FirstOrDefaultAsync(u => u.UserName == username || u.Email == username);
    
    if (user != null){
    var result = await _signInManager
                .PasswordSignInAsync(user.Email, password, false, false);
    }
    

提交回复
热议问题