为什么登录尝试在PasswordSignInAsync方法(ASP.NET)中返回{NotAllowed} [英] Why is the login attempt returning {NotAllowed} in the PasswordSignInAsync method (ASP.NET)

查看:55
本文介绍了为什么登录尝试在PasswordSignInAsync方法(ASP.NET)中返回{NotAllowed}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP.NET项目中使用了一个身份,它自动创建了登录和注册功能,注册完帐户后,我可以很好地注册到网站,并且我可以使用我制作的所有功能,但是如果我注销并尝试再次登录同一帐户,则登录过程始终失败.帐户被存储在数据库中,如下所示 https://i.imgur.com/M1EbfGj.png

I used an identity in my ASP.NET project, it created the login and register feature automatically and i can register to the website just fine, after registering the account gets logged in and i can use all the features i made, but if i log out and try to log into the same account again the login process always fails. The accounts are being stored in the database as following https://i.imgur.com/M1EbfGj.png

我没有更改Visual Studio 2019制作的代码,调试完所有我知道的是密码正确地传递到了数据库,但结果显示为{NotAllowed},发生的行是

I didn't change the code that was made by visual studio 2019 and after debugging all i know is that the password is passed correctly to the database but the result comes out as {NotAllowed}, the line where that happens is

var result = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure: false);
            

如果有人想查看整个项目,可以在 https://github.com/Alysty/中找到TaskManager

if someone wants to see the entire project it can be found in https://github.com/Alysty/TaskManager

推荐答案

最有可能是您遇到的文件:TaskManager/TaskManager/Areas/Identity/IdentityHostingStartup.cs

File that is most likely your issue: TaskManager/TaskManager/Areas/Identity/IdentityHostingStartup.cs

位置是要求在此行中确认帐户的位置:

Location is in requiring the account to be confirmed in this line:

services.AddDefaultIdentity<TaskManagerUser>(options => options.SignIn.RequireConfirmedAccount = true)

我的猜测是您的帐户未得到确认,因此您需要确认或删除此限制.

My guess is that your account is not confirmed so you need to confirm it or remove this constraint.

using System;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.UI;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using TaskManager.Areas.Identity.Data;
using TaskManager.Data;

[assembly: HostingStartup(typeof(TaskManager.Areas.Identity.IdentityHostingStartup))]
namespace TaskManager.Areas.Identity
{
    public class IdentityHostingStartup : IHostingStartup
    {
        public void Configure(IWebHostBuilder builder)
        {
            builder.ConfigureServices((context, services) => {
                services.AddDbContext<ApplicationDbContext>(options =>
                    options.UseSqlServer(
                        context.Configuration.GetConnectionString("ApplicationDbContextConnection")));

                services.AddDefaultIdentity<TaskManagerUser>(options => options.SignIn.RequireConfirmedAccount = true)
                    .AddEntityFrameworkStores<ApplicationDbContext>();
            });
        }
    }
}

这篇关于为什么登录尝试在PasswordSignInAsync方法(ASP.NET)中返回{NotAllowed}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆