.NET Core Identity problem z zalogowaniem się

0

Witam,

mam taki problem, otóż mam akcję logowania, wszystko przy debugowaniu jest ok oprócz tego, że użytkownik po wykonaniu tej akcji dalej jest niezalogowany :|
result, który sprawdza właściwością Succeded czy autoryzacja się powiodła jest na true, co tu się może dziać?

[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Login(LoginModel details, string returnUrl)
{
    if (ModelState.IsValid)
    {
        AppUser user = await userManager.FindByEmailAsync(details.Email);
        if (user != null)
        {
            await signInManager.SignOutAsync();
            Microsoft.AspNetCore.Identity.SignInResult result = await signInManager.PasswordSignInAsync(user, details.Password, false, false);
            if (result.Succeeded)
            {
                return Redirect(returnUrl);
            }
        }
        ModelState.AddModelError(nameof(LoginModel.Email), "Nieprawidłowa nazwa użytkownika lub hasło.");
    }
    return View(details);
}
0

Po czym sugerujesz że użytkownik nadal jest niezalogowany?

0

Za każdym razem wraca mi na stronę logowania, więc dodałem w widoku:

@if  (User.Identity.IsAuthenticated)
{
    <h5>Zalogowany</h5>
}
else
{
    <h5>Niezalogowany</h5>
}

i cały czas mam tekst "Niezalogowany"

0

Co kiedy ustawisz isPersistent na true?

0

Dalej to samo, nie wiem o co chodzi. W startupie mam:

public void ConfigureServices(IServiceCollection services)
{
    services.AddTransient<IPasswordValidator<AppUser>, CustomPasswordValidator>();
    services.AddTransient<IUserValidator<AppUser>, CustomUserValidator>();
    services.AddDbContext<AppIdentityDbContext>(options =>
        options.UseSqlServer(Configuration["ConnectionString"]));

    services.AddIdentity<AppUser, IdentityRole>()
        AddEntityFrameworkStores<AppIdentityDbContext>()
        AddDefaultTokenProviders();

    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}

public void Configure(IApplicationBuilder app)
{
    app.UseStatusCodePages();
    app.UseStaticFiles();
    app.UseDeveloperExceptionPage();
    app.UseMvcWithDefaultRoute();
    app.UseAuthentication();
}
1

Nie wiem czy to pomoze ale sprobuj wywolac app.UseAuthentication(); przed app.UseMvcWithDefaultRoute();. Tu masz moje repo gdzie mam ustawione Identity, moze wylapiesz inne roznice.

0

Stary dzięki, nie wpadłbym że tam kolejność ma znaczenie

1 użytkowników online, w tym zalogowanych: 0, gości: 1