[英]Cant login with asp.net core Identity
So I am working on a project.所以我正在做一个项目。 Everything seems fine.一切似乎都很好。 I dont have any error or anything like that.我没有任何错误或类似的东西。 But when I am trying to login into my website that I created with Identity, nothing happens.但是,当我尝试登录使用 Identity 创建的网站时,什么也没有发生。 All the tables are in my database as it should be.所有的表都在我的数据库中。
In the output in visual studio it says:在 Visual Studio 的 output 中它说:
info: GetThingsDoneMVC.Areas.Identity.Pages.Account.RegisterModel[0] User created a new account with password.信息:GetThingsDoneMVC.Areas.Identity.Pages.Account.RegisterModel[0] 用户使用密码创建了一个新帐户。
info: GetThingsDoneMVC.Areas.Identity.Pages.Account.LoginModel[0] User logged in.信息:GetThingsDoneMVC.Areas.Identity.Pages.Account.LoginModel[0] 用户登录。
So it works.所以它有效。 But when I try to login nothing happens.但是当我尝试登录时,什么也没有发生。 I get redirected to the home page and I still don't see that I am logged in. It still says up in the corner "Register" and "Login".我被重定向到主页,但我仍然没有看到我已登录。它仍然在角落里显示“注册”和“登录”。
Have anyone else had this problem before?以前有没有其他人遇到过这个问题? Any idea on how to fix this?关于如何解决这个问题的任何想法?
I also had it in the past and the problem was that I did not add @inject SignInManager<Identity> SignInManager
and @inject UserManager<Identity> UserManager
to the _LoginPartial.cshtml
file.我过去也有过,问题是我没有将@inject SignInManager<Identity> SignInManager
和@inject UserManager<Identity> UserManager
到_LoginPartial.cshtml
文件中。 Also make sure that in the _ViewImports.cshtml
file you have added @using Microsoft.AspNetCore.Identity
and @using Myproject.Models
if you have a seperate models project.如果您有单独的模型项目,还要确保在_ViewImports.cshtml
文件中添加了@using Microsoft.AspNetCore.Identity
和@using Myproject.Models
。
I fix the issue by going to the startup.cs and changing我通过转到 startup.cs 并更改来解决问题
services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true)
to至
services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = false) services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = false)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.