Asp.Net Core making unexpected logout

Asked

Viewed 69 times

0

I’m learning to work with Asp.Net Core, using version 2.1. After logging in, the system unexpectedly logs out, I could not find the reason, if it was error, wrong configuration... I’ve looked in tutorials, but I couldn’t find anything to help me.

This setting is wrong?

    public void ConfigureServices(IServiceCollection services) {
            services.Configure<CookiePolicyOptions>(options => {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });    

            // Registrando o banco de dados
            services.AddDbContext<Unitins_MVC_SecurityContext>(o =>
            o.UseLazyLoadingProxies() // Usando lazy loading
            .UseLoggerFactory(MyLoggerFactory) // Log do banco de dados para ver as saídas sql geradas no Output do VS2017 em modo debug
            .UseSqlServer(config.Database.ConnectionString));

            // Usando classes customizadas no Identity
            services.AddIdentity<Pessoa, Grupo>().AddDefaultTokenProviders();

            services.AddScoped<SignInManager<Pessoa>, SignInManagerPessoa>();
            services.AddScoped<UserManager<Pessoa>, UserManagerPessoa>();
            services.AddScoped<IPasswordHasher<Pessoa>, VerificaSenhaAD>();

            // Usando um custom storage para controlar usuários no Identity
            services.AddTransient<IUserStore<Pessoa>, PessoaStore>();

            // Usando um custom storage para controlar permissões no Identity
            services.AddTransient<IRoleStore<Grupo>, GrupoStore>();

            services.AddSession();

            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
                .AddCookie(options => {
                    options.LoginPath = PathString.FromUriComponent("/Account/Login");
                    options.SlidingExpiration = true;
                    options.ExpireTimeSpan = TimeSpan.FromDays(7); // TODO Tempo de inatividade para pedir novamente o login
                });

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

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) {

            Func<string, LogLevel, bool> filter = (name, level) => level >= LogLevel.Error;
            //loggerFactory.AddConsole(filter);
            loggerFactory.AddContext(filter, config.Database.ConnectionString, config.NomeAplicacao);

            //app.UseDeveloperExceptionPage();

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

            app.UseAuthentication(); // Vamos usar autenticação
            app.UseStaticFiles();
            app.UseCookiePolicy();            
            app.UseSession();
            app.UseHttpContext();

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

Thanks in advance for the help.

[EDIT] When I click frantically on any link, the application simply logout :( I’ve never seen it anywhere

  • Tries to remove SlidingExpiration, I don’t know exactly what he does, but there’s something talking about him here: https://answall.com/a/221167/102836 Maybe that’s it.

  • Turn off the options.Checkconsentneeded and test, please.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.