ASP .NET Core Identity SignInManager

K. Alex

Good day. ASP.NET-Core project was with out authentication. So, I tried to add built-in Identity for this purpose. Tables in database successfully created, new user registered. In Account controller in Login Method SignInManager return success in process. In partial view, where links for Login\Register added injection and library (all looks as default project with authentication, based on its implementation):

@using Microsoft.AspNetCore.Identity
@inject SignInManager<ApplicationUser> SignInManager

Then in view checking:

SignInManager.IsSignedIn(User)

After Login it's always false, irrelevant moment ago state for login in controller was success. Have I missed to add something at Configuration in Startup.cs or some else? Implemented all things as in default VS project with authentication.

Upd. Configuration in Startup.cs

public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContext<ApplicationDbContext>(options =>
        options.UseMySql("Server=; Database=; Uid=;Pwd=;"));

        services.AddIdentity<ApplicationUser, IdentityRole>(options =>
        {
            options.Password.RequireDigit = true;
            options.Password.RequiredLength = 6;
            options.Password.RequireNonAlphanumeric = false;
            options.Password.RequireUppercase = true;
            options.Password.RequireLowercase = false;

            options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(5);
            options.Lockout.MaxFailedAccessAttempts = 5;

            options.User.RequireUniqueEmail = true;
            options.SignIn.RequireConfirmedEmail = true;
        })
            .AddEntityFrameworkStores<ApplicationDbContext>()
            .AddDefaultTokenProviders();

        // Here added my application services. 
        .......

        services.AddMvc();
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {

        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseBrowserLink();
            app.UseDatabaseErrorPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
        }

        app.UseStaticFiles();

        app.UseAuthentication();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });
    }
etrupja

In your ConfigureServices method configure cookies as well. Something like below:

...
// Here added my application services. 
.......
services.ConfigureApplicationCookie(options => 
{
     options.Cookie.HttpOnly = true;
     options.Cookie.Expiration = TimeSpan.FromDays(5);
     options.LoginPath = "/Account/Login";
 });

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Creating a custom SignInManager in Asp.Net Core 3 Identity

Asp.NET Identity Custom SignInManager

ASP.NET Core 2.0 Identity: SignInManager.IsSignedIn(User) returns false after signing in

In ASP.net core Identity (UserManager & SignInManager) is it possible to ban a user immediately?

How to get user claims after signin through SignInManager in ASP .NET CORE Identity?

Can I automatically log back into my SignInManager and UserManager (Identity) via using cookies -> Asp.Net-Core Identity (Deployed live)

SignInManager not recognized in asp.net core 2

ASP.NET Identity Provider SignInManager Keeps Returning Failure

ASP.NET Identity AuthenticationManager vs. SignInManager and cookie expiration

How to use ASP.net Core 1 "SignInManager" without EntityFramework

ASP.net Core 1 “SignInManager” without EntityFramework Extended Example

SignInManager constructor changes when not in ASP.NET Core web project

ASP.Net Identity 2.1 alpha SignInManager.GetVerifiedUserIdAsync invalid cast

Asp.Net Core extending Identity

Seeding asp.net core Identity Role

Add UserClaim with Identity asp.net core

ASP NET CORE Identity and Checktoken URL

ASP.NET Core Identity with Windows Authentication

Clean Architecture and Asp.Net Core Identity

ASP .NET Core Identity custom ApiAuthorizationDbContext

In ASP.NET Core Identity, what is a ticket?

ASP.NET Core Identity user groups

Customizing ASP.NET Core Identity Tables

DocumentDb Identity Provider for ASP.NET Core

Asp.Net Core Identity RedirectToAction

Updating Identity in ASP.NET Core 2.0

ASP.NET Core Identity Settings Not Working

ASP.NET Core MVC MySQL Identity

ASP.Net Core Identity with distributed session