Membership in ASP.NET MVC - the user often logs out - I don’t know why

I have an ASP.NET MVC 4 web application. Running locally, it works fine, but on a web host (which uses shared hosting), the logged in user often logs out of the system, redirecting back to the home page. In most cases, the user logs out after just a few steps.

The website host suggested that my application might use too much memory, but I used the program to profile memory usage, and I confirmed that it does not use excessive amounts of memory - in fact, the application seems to use a fraction of the allocated memory on the web host.

Here's the login method used:

public static Boolean Login(string Username, string Password, bool persistCookie = false) { bool success = Membership.ValidateUser(Username, Password); if (success) { FormsAuthentication.SetAuthCookie(Username, persistCookie); } return success; } 

In my web hosting, the form validation timeout is set to 60 minutes, so that shouldn't be a problem, right?

 <authentication mode="Forms"> <forms loginUrl="~/Account/Login" timeout="60" /> </authentication> 

and the session state timeout value is also set to 60 minutes:

 <sessionState mode="InProc" customProvider="DefaultSessionProvider" timeout="60"> 

Based on the answer here , I added this line as well, which didn't seem to solve the problem:

 <machineKey validationKey="AutoGenerate,IsolateApps" decryptionKey="AutoGenerate,IsolateApps"></machineKey> 

Any ideas on what might be the problem, and what can I do to solve the problem?

+6
source share
2 answers

Your sessions are not syncing. IIS crash. Because you are using memory sessions, every time IIS crashes, your sessions disappear and the user logs off. You should check the server event presentation and examine the error details to find out what the error is.

+1
source

I set my 2880 timeout to authentication timeout for web.config and I also set sessionState before closing system.web

 <sessionState timeout="1440"></sessionState> 

This will support the session for 24 hours.

0
source

Source: https://habr.com/ru/post/943988/


All Articles