I keep getting logged out

Cerbo Estúdio 1 Reputation point
2022-12-16T19:51:40.737+00:00

Hello there.

I have a web application running using .NET 5.0 and Razor pages that keeps logging me out every 1-2 minutes on my production environment. The same app, runinng local doesn't do that.

I have cookies configured on my startup.cs file like this:

services.AddDefaultIdentity<Usuario>(options =>
{
options.SignIn.RequireConfirmedAccount = false;
options.Password.RequiredLength = 8;
options.Password.RequiredUniqueChars = 3;
options.Password.RequireDigit = false;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = false;
options.Password.RequireLowercase = false;
})
.AddRoles<IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddRazorPages(options =>
{
options.Conventions.AuthorizeFolder("/Admin");
options.Conventions.AuthorizeFolder("/Fotografo");
});

        services.AddAntiforgery(o => o.HeaderName = "XSRF-TOKEN");  

        services.ConfigureApplicationCookie(options =>  
        {  
            options.Cookie.Name = "user_site";  
            options.LoginPath = "/Login";  
            options.ExpireTimeSpan = TimeSpan.FromMinutes(60);  
            options.SlidingExpiration = true;  
            options.ReturnUrlParameter = CookieAuthenticationDefaults.ReturnUrlParameter;  
        });  

And as you can see on the attached image, the cookie is correctly set in the website271420-cookie.jpg
The problem happens when I log in in the /Admin folder, then after a few minutes I try to access another page inside the same folder, the app will redirect me to the login page with the page that I tried to access as a ReturnURL parameter. On my local environment this doesn't happen, only on the production. Could you help me to identify why this happens and how could I fix it?

Thank you very much.

Developer technologies | .NET | Entity Framework Core
Developer technologies | ASP.NET | ASP.NET Core
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 78,006 Reputation points Volunteer Moderator
    2022-12-16T21:33:28.917+00:00

    not enough information. maybe the site is recycling.

    use the browser tools to track the if the cookie is sent.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.