当我使用IIS Express Identity运行应用程序时,登录工作正常,但是当我使用.NET Core应用程序运行时.dll文件登录不起作用。
var result =
await _signInManager.PasswordSignInAsync(model.Username, model.Password, model.Remember, false);
is successful but :
bool isAuthenticated = User.Identity.IsAuthenticated;
总是返回假。
public async Task<IActionResult> Login(LoginViewModel model, string returnUrl = null)
{
var result =
await _signInManager.PasswordSignInAsync(model.Username, model.Password, model.Remember, false);
if (result.Succeeded)
{
var user =await _userManager.FindByNameAsync(model.Username);
UserProfile.UserId = user.Id;
await _signInManager.SignInAsync(user, isPersistent: false);
return RedirectToAction("Index", "Dashbaord");
}
TempData["Message"] = "Error";
return RedirectToAction("Login");
}
我在应用程序上强制执行 HTTPS,然后我的应用程序运行良好!
https://learn.microsoft.com/en-us/aspnet/core/security/enforcing-ssl?view=aspnetcore-2.2&tabs=visual-studio