SignInManager.IsSignedIn (Пользователь) возвращает false - PullRequest
0 голосов
/ 17 апреля 2020

Я работаю над проектом ASP. NET Core 3.1 Web Application. Я использовал идентификацию для аутентификации и установил пакет Microsoft.AspNetCore.Identity.EntityFrameworkCore в проект. Код входа был реализован следующим образом:

public async Task<IActionResult> Login(LoginDto login, string returnUrl)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var result =
                    await _signInManager
                    .PasswordSignInAsync(login.Email, login.Password, login.RememberMe, false);

                if (result.Succeeded)
                {
                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index","Home");
                    }
                }
                else
                    ModelState.AddModelError(string.Empty, "Invalid login attemp.");
            }

            return View(login);
        }

А вот как выглядит конфигурация запуска:

 public void ConfigureServices(IServiceCollection services)
        { 
        services.AddDbContext<IdentityDbContext>
            (options => options.UseSqlServer(Configuration.GetConnectionString("MusicTutorialIdentityConnection")
            , optionsBuilder =>
         optionsBuilder.MigrationsAssembly("MusicTutorial.Mvc"))); 

            services.AddIdentity<IdentityUser, IdentityRole>()
                .AddEntityFrameworkStores<IdentityDbContext>()
                .AddDefaultTokenProviders();

        }
 public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthorization();

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

Проблема в том, что SignInManager.IsSignedIn(User) всегда возвращает false, когда я пытаюсь войти в систему Вот коды _layout.chHtml, где этот метод называется:

image

А вот изображение браузера:

enter image description here

...