473,732 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2611
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*******@disc ussions.microso ft.com> wrote in message
news:6B******** *************** ***********@mic rosoft.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
7149
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 getName() as String dim name as string name = "Abc" return name end function
1
1380
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 Start of the app. some are created at start of the request. I assume that these variables in the global.asax file is "server side", therefore they do not travel to the clients. John
8
6845
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 code-behind and in business logic (C# classes used by the aspx) lose their value. I cannot reproduce this on our development server, so I cannot understand what the cause of all this is. We are using asp.net 1.1 with IIS6 on win2003.
6
1141
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#" Classname="myGlobal" %> <script runat="server"> public static int UserID = 0; void Session_Start(Object sender, EventArgs e) {...}
2
5207
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 file, and what would I do to access it? (I am using VB.NET for my code) Thanks. -- Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/
2
2370
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 variable is goTest, I thought I can reference it as Global.goTest but I see that I cannot. Thanks.
8
2002
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 like to get the list of the users Session Variables there were there at the time of the error. But if I add the following line: MyMessage.Body &= "Session Variable" & session("JobTitle") & vbCrLf it goes back to the MS error page instead of...
2
1897
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 timer I am using as a service every 10 minutes to send email to users. OK so all is fine until I need to load a file from the server (in fact an email template).
5
1855
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
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8774
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9447
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9307
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9181
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.