Logout (ASP.NET)

I programmed the website, prepared the login mechanism (through the text box, not the login tools), users want to log out, they click the logout button. However, my problem is that if users do not click the logout button or close the web page or switch another, how can I understand this situation?
According to my mechanism, when users log off, the DB performs input and delete operations.
I also want to do this with a cover page, switch another.
Thank.

+3
source share
6 answers

It looks like you are doing a DB operation when you log out, and when people just move around without pressing the exit button, the code does not work.

In your global.asax take a look at session_end. Perhaps you can post your operation there.

protected void Session_End(Object sender, EventArgs e) 
{ 
    // Your code goes here. Since your logout code probably relied on the user being
    // logged in, you might end up checking Request.IsAuthenticated here. Why? Because
    // this event fires any time a session ends -- even if the user is not logged in! 
}

Note that if you use this, it actually fires when the IIS session ends, and not when the browser closes. By default, a session expires after 20 minutes of inactivity.

Once you implement this, you can start your Session.Abandon session exit page, which will call Session_End. It seems to me clean.

Here's an MSDN link with more information about session events: http://msdn.microsoft.com/en-us/library/ms178583.aspx

+14
source

, , , , , javascript/AJAX, 10 , : " ". , , , 20 , X , , .

+1

- 20 , 20 , = . session_end global.asax, .

, - - , 1 .

, - - -, , .

, keep alive. , . AJAX Javascript , iFrame.

. : ASP.NET AJAX . ?

+1

, , , cookie, , cookie , . cookie , , , , .

0

, , (- ), . 30 . , , .

0

may want to check events in global.asax . You can update db with session_end event. You can also use the beginrequest event, which is fired on each page and monitored (you will receive several hits on the page if you have several controls). You can also put something in your page_load event.

0
source

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


All Articles