I think this is due to that HttpContext is valid only for the request processing. Session_End event is getting called separately from any requests, so that no
HttpContext exists.
Never ask users what they want, or they'll tell you
You cant, because it not guaranteed to be executed, unless you save your session in sql server--inproc. So atleast you will know the event is firing. In my opinion that should return a null anyways..
Please Mark Post that helped you as answer, also include a summary of what solved the problem as it helps others in similar situations
ArtemL: i'm not sure but i think i already tried Session["username"] <== this also return null in global. I'll try what u suggest and return the answer THX.
remark, i tried to set the username in .dll not in the page, thus some object cannot be referneced in the library.
naturehermit: if i can't do logoff in session_end, what actully should be in there then??? could u give me some idea or concept of this event? THX
Even if you can't see it, it doesn't mean it isn't there...
What I meant was that current username ins session_end event in globals.asax will return null as the user would not exist for session_end event to fire.
As long as you are in InProc session state, it should fire. If the session state is set to use a state server or SQL Server, session_end will never fire.
Unfortunately there isn't a really easy way to-do this - since the Session_End event isn't always guarenteed to fire and so you need to be careful about what assumptions you make on it.
Probably the easiest way to implement this would be to write your own custom HttpModule that you plug into ASP.NET
Please Mark Post that helped you as answer, also include a summary of what solved the problem as it helps others in similar situations
I strongly agree with you and found that when the user closes the brower the session_end does not fire but if time out it does. So i understand ArtemL's first qoute that maybe there's not the request sent to server make the session_end doesn't fire too.
but when i navigate back to the page which has Logoff button i still can get the current user name from that page request (may be the cookies still alive). so i wonder what if i want to logoff the current user in this case (timeout) what should i do. Transfer
to logout page and let the logout page get the current user ? or what else i can do.
what does the real world normally do when time out?
P.S. my system will not kick off the current user if second session (with same ID) is logging in. the first one is priority that's y we must need logoff function to allow the second session.
Even if you can't see it, it doesn't mean it isn't there...
spncc
Member
11 Points
24 Posts
How can i get the current username in Session_End in Global.asax
Jul 19, 2007 02:50 AM|LINK
in the Session_End event, i'm trying to get the current username by using
ArtemL
Participant
1258 Points
251 Posts
Re: How can i get the current username in Session_End in Global.asax
Jul 19, 2007 07:30 AM|LINK
I think this is due to that HttpContext is valid only for the request processing. Session_End event is getting called separately from any requests, so that no HttpContext exists.
spncc
Member
11 Points
24 Posts
Re: How can i get the current username in Session_End in Global.asax
Jul 19, 2007 08:08 AM|LINK
o, ic.
so how do i get the current username for that session then ???
Thx
ArtemL
Participant
1258 Points
251 Posts
Re: How can i get the current username in Session_End in Global.asax
Jul 19, 2007 08:48 AM|LINK
Did you try to use HttpApplication.Session property?
naturehermit
Star
14610 Points
3046 Posts
Re: How can i get the current username in Session_End in Global.asax
Jul 19, 2007 10:36 AM|LINK
You cant, because it not guaranteed to be executed, unless you save your session in sql server--inproc. So atleast you will know the event is firing. In my opinion that should return a null anyways..
spncc
Member
11 Points
24 Posts
Re: How can i get the current username in Session_End in Global.asax
Jul 19, 2007 02:20 PM|LINK
ArtemL: i'm not sure but i think i already tried Session["username"] <== this also return null in global. I'll try what u suggest and return the answer THX.
remark, i tried to set the username in .dll not in the page, thus some object cannot be referneced in the library.
naturehermit: if i can't do logoff in session_end, what actully should be in there then??? could u give me some idea or concept of this event? THX
naturehermit
Star
14610 Points
3046 Posts
Re: How can i get the current username in Session_End in Global.asax
Jul 19, 2007 02:42 PM|LINK
What I meant was that current username ins session_end event in globals.asax will return null as the user would not exist for session_end event to fire.
As long as you are in InProc session state, it should fire. If the session state is set to use a state server or SQL Server, session_end will never fire.
Unfortunately there isn't a really easy way to-do this - since the Session_End event isn't always guarenteed to fire and so you need to be careful about what assumptions you make on it.
Probably the easiest way to implement this would be to write your own custom HttpModule that you plug into ASP.NET
spncc
Member
11 Points
24 Posts
Re: How can i get the current username in Session_End in Global.asax
Jul 19, 2007 03:31 PM|LINK
I strongly agree with you and found that when the user closes the brower the session_end does not fire but if time out it does. So i understand ArtemL's first qoute that maybe there's not the request sent to server make the session_end doesn't fire too.
but when i navigate back to the page which has Logoff button i still can get the current user name from that page request (may be the cookies still alive). so i wonder what if i want to logoff the current user in this case (timeout) what should i do. Transfer to logout page and let the logout page get the current user ? or what else i can do.
what does the real world normally do when time out?
P.S. my system will not kick off the current user if second session (with same ID) is logging in. the first one is priority that's y we must need logoff function to allow the second session.
naturehermit
Star
14610 Points
3046 Posts
Re: How can i get the current username in Session_End in Global.asax
Jul 23, 2007 08:47 AM|LINK
What is it that you would like to do at this point in time??
spncc
Member
11 Points
24 Posts
Re: How can i get the current username in Session_End in Global.asax
Jul 23, 2007 10:14 AM|LINK