473,394 Members | 1,971 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Accessing Public Variables from Global.asax

I have an application that allows users to login and logout. I track how
many users are logged in and when each individual is logged in. The
application will not allow concurrent logins(let a user log in twice at the
same time). My problem is I am having trouble telling when the user is
logged off. If they click the logout button everything works fine. But if
the close the browser by clicking the x or navigate to another url through
the address bar I will get no indication that they have logged off. To
remedy that I placed the code to logoff the user in the Session_End method
of the Global.asax page. But there is a problem with this as well. I need
the user ID to perform the logoff tasks. I can't get this from a session
object because by the time the Session_End method is reached the session
object I previously created is destroyed. I tried using a public variable to
hold the user ID but I can not get access to it in the global.asax. I also
tried to place the user ID in a public shared variable, but this causes the
user ID to be overwritten whenever a new user logs in. Is there any way to
create a public variable that I can access from the global.asax page that is
not shared among application instances? Should I be looking at this from
another angle? Any ideas or help would be greatly appreciated.
Nov 18 '05 #1
2 2588
I would create a hashtable (aka Dictionary) in application scope that tracks logins and last accessed timestamps. I would create a helper class that manages synchronizing your hashtable with objects in session. Each time Session_End is called I'd look at the hashtable and remove any old records. I'd also remove the record if the user clicks "logout". And of course, if a entry is found in the hashtable don't let the user log in. Each hashtable entry would store the login as a key and timestamp as the item

Joe Agste
www.geekyfrog.com
Nov 18 '05 #2

Joe,

I tried something similar to this before. The only problem was that I had
know way of knowing which user was logging of when they hit Session_End.
For example, say two users logon at the same time, userA & userB. Then lets
say that userB's session times out and userA's session is still active. How
would I be able to tell it is userB that I need to logoff and not userA, or
vice versa? There is nothing that identifies who's session timed out.
Please let me know if I misunderstood your advice. Thanks for taking the
time to help!

Luke

"Joe Agster" <an*******@discussions.microsoft.com> wrote in message
news:6B**********************************@microsof t.com...
I would create a hashtable (aka Dictionary) in application scope that tracks logins and last accessed timestamps. I would create a helper class
that manages synchronizing your hashtable with objects in session. Each time
Session_End is called I'd look at the hashtable and remove any old records.
I'd also remove the record if the user clicks "logout". And of course, if a
entry is found in the hashtable don't let the user log in. Each hashtable
entry would store the login as a key and timestamp as the item.
Joe Agster
www.geekyfrog.com

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Anjali Lourda | last post by:
Hi, I have defined a function in global.asax file. Could somebody please tell me how i am supposed to call that function from the other files of the same project. Global.asax public function...
1
by: WJ | last post by:
I am storing my global variables in the application "global.asax" file, some are nd some are not sensitive. Is it OK to store sensitive data on Global variables. Please note: some are created at...
8
by: Simone Chiaretta | last post by:
I've a very strange behaveour related to a website we built: from times to times, something should happen on the server, and all static variables inside the web application, both defined inside aspx...
6
by: Daves | last post by:
can anyone imagine why I cannot access static variables in my global class from other pages, eg: myNumber = myGlobal.UserID; where global.asax contains: <%@ Application Language="C#"...
2
by: Nathan Sokalski | last post by:
I would like to access variables and functions that I declare in the Global.asax.vb file. However, I am having trouble doing that. What does the declaration have to look like in the Global.asax.vb...
2
by: vvenk | last post by:
Hello: I have defined public variables in Global.asax.vb that are initialized in the application_start event. How do I reference these variables in other ASP forms? For example, if my...
8
by: tshad | last post by:
I have an Application_Error function in my Global.asax function that works fine until I try to access my Session variables. I am emailing the results to myself whenever I get an error and would...
2
by: rgparkins | last post by:
Hi Guys Maybe a simple and easy solution to this, but I keep getting exception object not set to instance etc etc. I have a Timer that is initiated in Application_Start in Global.asax. This...
5
by: John | last post by:
Hi Is there a way to declare public functions that can be accessed in any aspx page? Can global variables be declared? Thanks Regards
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.