Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Aug 19, 2009 05:39 AM by venkatu2005
Jul 19, 2007 02:50 AM|LINK
in the Session_End event, i'm trying to get the current username by using
but it seems the HttpContext.Current is null. So I try to set session variable (in validateUser membership overriden class) by using
but it seems the HttpContext.Current is null too. How or what can i do?
Y does the httpContext.Current is null in session end?
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
Jul 19, 2007 08:08 AM|LINK
so how do i get the current username for that session then ???
Jul 19, 2007 08:48 AM|LINK
Did you try to use HttpApplication.Session property?
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..
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
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
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.
Jul 23, 2007 08:47 AM|LINK
What is it that you would like to do at this point in time??
Jul 23, 2007 10:14 AM|LINK