Saving a session in real time C #

I use HttpWebRequest to log in to a website and receive a session cookie. My application resets certain pages and eventually becomes inactive, which leads to the death of the session.

What would be a good way to prevent this and just be curious how web browsers do it?

+2
source share
3 answers

Browsers themselves do not. They only do this if the web application itself supports it. For example, there may be some javascript that makes an AJAX request every 30 seconds or so to send a keep-session-alive request to the server, which will then go over and update the status information to reflect that the “most recent activity” now, and therefore prevents the session timeout.

In the above example, however, the “client”, that is, the html / javascript in the browser, and the “server” would be written together and therefore this type of inline function.

, , "keep-alive", -, javascript, "keep-alive" ( SetTimeout, SetInterval js-, ). , , "" , (.. ).

+3

, , , 10-15 .

+1

: x-, , . - :

(Javscript/JQuery)

$(function() {
        setInterval(function() { $.post("/KeepSessionAlive.ashx", null, null); }, 60000 );
    });

Server: In the KeepSessionAlive file on the server, you write something in the session, fe:

context.Session["KeepSessionAlive"] = DateTime.Now;
0
source

All Articles