Ali Besharati
Ali Besharati

Reputation: 1046

Authorize is not authenticating action asp.net core 2.0 with cookies

I am building a web app in Asp.net core 2.0 mvc-template i set the ExpireTimeSpan to 365 Days but when i close the browser and after few minutes i came back to the site , it redirect me to the login path, i check the cookies where stored in the browser and i see the cookie is set to 365 Days later,here my implication where did i make a mistake?

in my ConfigureServices methode:

  public void ConfigureServices(IServiceCollection services)
    {

        services.AddDbContext<ApplicationDbContext>(options =>
         options.UseSqlite("Data Source=DataBaseContext.db"));
        services.AddIdentity<ApplicationUser, IdentityRole>(option =>
               {
                   option.Password.RequireDigit = false;
                   option.Password.RequiredLength = 5;
                   option.Password.RequireLowercase = false;
                   option.Password.RequireNonAlphanumeric = false;
                   option.Password.RequireUppercase = false;
                   option.User.RequireUniqueEmail = false;
               }
            )
            .AddEntityFrameworkStores<ApplicationDbContext>()
            .AddDefaultTokenProviders(); 
                  services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
        .AddCookie();

        services.ConfigureApplicationCookie(Option => {
            Option.LoginPath = "/Account/UserChalenge";
            Option.ExpireTimeSpan = TimeSpan.FromDays(365);
            Option.SlidingExpiration = true;
            });
        // Add application services.
        services.AddTransient<IEmailSender, EmailSender>();
        services.AddDetection();
        services.AddMvc().AddSessionStateTempDataProvider().AddCookieTempDataProvider();
        services.AddSession();


    }

and in Configure methode :

        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.UseSession();
       // ... use mvc template

        });


    }

Upvotes: 0

Views: 98

Answers (1)

Ali Besharati
Ali Besharati

Reputation: 1046

just contact your hosting provider to set Load user profile=true in iis setting

Upvotes: 0

Related Questions