Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 353 Vote(s) - 3.45 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Session_End does not fire?

#1
I want to sign out a user when his session times out. So used following code in Global.asax:

protected void Session_End(object sender, EventArgs e)
{
FormsAuthentication.SignOut();
}

But seems `session_end` never fires. Any idea how can fix it? I'm using ASP.NET with default settings.
Reply

#2
Are you sure that it never fires ?

As I understand it `Session_End` has nothing to do with the current request because ASP.NET session is terminated by the timeout AFTER the last request from the client has arrived. The call to `FormsAuthenticaion.SignOut` manipulates authentication cookies and therefore has no effect without any connectivity from the client (browser).

Take a look at this question (which has an answer) - the problem is more or less similar to yours so you might find a right solution:

[Session_End in Global.asax.cs not firing using forms authentication][1]

Hope this helps.


[1]:

[To see links please register here]

Reply

#3
In your web.config you need to have the sessionState element as a child of the <system.web> element

<configuration>
<system.web>
<sessionState mode="InProc" />
.....
</system.web>
</configuration>
Reply

#4
You may set some Session data in Session_Start. Without this, Session_End will not be fired.
see [this][1]

> Also another very important thing to note here is that if you do not save anything in the session the Session_End event will not fire. There must be something saved in the session atleast once for the Session_End event to fire. This also means that if you save something in the session in the first request and abandon the session in the same request the Sesison_End event will not fire, as there was nothing saved in the session ever.


[1]:

[To see links please register here]

Reply

#5
I dont know how its working, but it will fire when i close my browser after time out period.

public void Session_End(Object sender, SessionEndedEventArgs e)
{
}
Call this from

Application_Start() Event

SessionEndModule.SessionEnd += new SessionEndEventHandler(Session_End);
Reply

#6
I don't know if it is a feature or bug. Or may be I don't understand enough session managment in ASP.NET. But this is what I found.

Session_End does not fire in ASP.NET MVC 4 (with default settings for sessionState element in web.config) if Session_Start is not declared.

So you need declare Session_Start to catch Session_End :)

protected void Session_Start(Object sender, EventArgs e) { }

protected void Session_End(Object sender, EventArgs e) {
Debug.WriteLine("End. " + Session.SessionID);
}
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through