.net core _IsSignedIn(用户)表示用户在成功登录后未登录

.net core _IsSignedIn(用户)表示用户在成功登录后未登录,.net-core,asp.net-core-mvc,authorization,.net Core,Asp.net Core Mvc,Authorization,我正在使用自定义用户/角色存储,并且我可以成功执行登录: [HttpPost] public async Task<IActionResult> Login(UserAccount user) { var result = await _signInManager.PasswordSignInAsync(user.UserName, user.Password, false, false); if (result.Succe

我正在使用自定义用户/角色存储,并且我可以成功执行登录:

    [HttpPost]
    public async Task<IActionResult> Login(UserAccount user)
    {

        var result = await _signInManager.PasswordSignInAsync(user.UserName, user.Password, false, false);

        if (result.Succeeded)
        {
            return RedirectToAction(nameof(CompanyController.Index));
        }

        return RedirectToAction(nameof(CompanyController.Login), new {error = true});

    }
[HttpPost]
公共异步任务登录(用户帐户用户)
{
var result=wait _signInManager.PasswordSignInAsync(user.UserName,user.Password,false,false);
if(result.successed)
{
返回重定向到操作(名称(CompanyController.Index));
}
返回RedirectToAction(nameof(CompanyController.Login),new{error=true});
}
但是,用户主体用户没有反映这一点,因为它表示在注销控制器中的签入过程中用户没有登录:

    public async Task<IActionResult> Logout()
    {

        if (_signInManager.IsSignedIn(User))
        {
            await _signInManager.SignOutAsync(); // will never get to this point, even after successful login
        } 

        return RedirectToAction(nameof(HomeController.Index), nameof(HomeController).Replace("Controller", ""));
    }
public异步任务注销()
{
if(_signInManager.IsSignedIn(用户))
{
wait _signInManager.SignOutAsync();//即使在成功登录之后,也永远不会到达这一点
} 
返回RedirectToAction(nameof(HomeController.Index)、nameof(HomeController.Replace)(“Controller”);
}
管理器的初始化:

    UserManager<UserAccount> _userManager;
    RoleManager<Role> _roleManager;
    SignInManager<UserAccount> _signInManager;
    DatabaseContext _db;

    public CompanyController(UserManager<UserAccount> userManager, RoleManager<Role> roleManager, 
            SignInManager<UserAccount> signInManager, DatabaseContext context)
    {
        _userManager = userManager;
        _roleManager = roleManager;
        _signInManager = signInManager;
        _db = context;
    }
UserManager\u UserManager;
角色经理(rolemanger);
SignInManager\u SignInManager;
数据库上下文数据库;
上市公司控制者(用户管理者用户管理者角色管理者角色管理者,
SignInManager SignInManager,数据库上下文)
{
_userManager=userManager;
_roleManager=roleManager;
_signInManager=signInManager;
_db=上下文;
}
我以为用户负责人会跟踪这一点,但似乎没有。有人知道为什么吗

编辑:

Startup.cs ConfigureServices()中的所有内容都是正确的:

public void配置服务(IServiceCollection服务)
{
services.AddDbContext(选项=>
{
options.UseMySql(Configuration.GetConnectionString(“MySQLConnection”);
});
服务.附加性(选项=>
{
options.Password.RequireDigit=false;
options.Password.RequireUppercase=false;
options.Password.RequireUppercase=false;
options.Password.RequiredLength=1;
options.Password.RequireNonAlphanumeric=false;
})
.AddDefaultTokenProviders();
services.AddTransient();
services.AddTransient();
services.AddControllersWithViews();
}
失败,因为Startup.cs Configure()中缺少一行:

public void配置(IApplicationBuilder应用程序,IWebHostEnvironment环境)
{
// ....
app.UseRouting();
app.UseAuthentication();//
{
endpoints.MapControllerRoute(
名称:“默认”,
模式:“{controller=Home}/{action=Index}/{id?}”);
});
}

你能分享一下你是如何在
Starup.cs
中注册身份的吗?
public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContext<DatabaseContext>(options =>
        {
            options.UseMySql(Configuration.GetConnectionString("MySQLConnection"));
        });

        services.AddIdentity<UserAccount, Role>(options =>
        {
            options.Password.RequireDigit = false;
            options.Password.RequireUppercase = false;
            options.Password.RequireUppercase = false;
            options.Password.RequiredLength = 1;
            options.Password.RequireNonAlphanumeric = false;
        })
        .AddDefaultTokenProviders();

        services.AddTransient<IUserStore<UserAccount>, CustomUserStore>();
        services.AddTransient<IRoleStore<Role>, CustomRoleStore>();

        services.AddControllersWithViews();
    }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        // ....
        app.UseRouting();

        app.UseAuthentication(); // <== THIS LINE WAS MISSING
        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllerRoute(
                name: "default",
                pattern: "{controller=Home}/{action=Index}/{id?}");
        });
    }