【问题标题】:Logs out of account for no reason无缘无故退出账户
【发布时间】:2021-05-11 14:53:15
【问题描述】:

我正在开发一个 Web 应用程序,但是,我遇到了一个问题。授权后的某个时间,无缘无故退出该帐户。我不明白问题是什么。可能是什么问题?

配置服务:

public void ConfigureServices(IServiceCollection services)
{
    string connectionString = Configuration.GetConnectionString("DefaultConnection");

    services.AddDbContext<ApplicationDbContext>(config =>
    {
        config.UseSqlServer(connectionString);
    });

    services.AddDefaultIdentity<IdentityUser>(config =>
    {
        config.Password.RequireDigit = true;
        config.Password.RequireLowercase = true;
        config.Password.RequireNonAlphanumeric = true;
        config.Password.RequireUppercase = true;
        config.Password.RequiredLength = 8;
    })
    .AddEntityFrameworkStores<ApplicationDbContext>();

    services.ConfigureApplicationCookie(config =>
    {
        config.LoginPath = "/Account/Login";
    });

    services.AddMvc();
}        

登录操作:

[AllowAnonymous]
public async Task<IActionResult> Login()
{
    await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);

    return View();
}

[HttpPost]
[AllowAnonymous]
public async Task<IActionResult> Login(LoginBindingModel model)
{
    if (!ModelState.IsValid)
    {
        return View(model);
    }

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

    if (!result.Succeeded)
    {
        ModelState.AddModelError("Email", "Неверный логин или пароль.");

        return View(model);
    }

    return RedirectToAction("Index", "Home");
}
        

【问题讨论】:

标签: c# asp.net-core


【解决方案1】:

由于会话超时。

服务器上的默认会话超时为 20 分钟,但可配置。微软。 AspNetCore。 Session 包提供中间件来管理 ASP.NET Core 中的会话。

查看此内容以获得更详细的视图。

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/app-state?view=aspnetcore-5.0

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-11
    • 2019-04-14
    • 1970-01-01
    • 2020-06-25
    • 1970-01-01
    • 2017-04-11
    • 1970-01-01
    • 2023-04-03
    相关资源
    最近更新 更多