473,395 Members | 1,956 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,395 software developers and data experts.

Problem with public static hashtable in C#

am using Visual Studio 2003, .Net Framework 1.1, C#. I get a SystemNullReferenceException when trying to do a hashtable.add(string,string) from a login page, and I do not understand why because all of the other data items from the Global.asax.cs are accessible in my pages. The key and value are not null (according to the watch window), so it is something else. This is likely something retarded, so I apologize in advance. It is my first attempt at a hash table. I am trying to store userid and sessionid for logging, statistics, troubleshooting (lol), etcetera.

Code Snippit from Global.asax.cs
public class Global : System.Web.HttpApplication
{

private System.ComponentModel.IContainer components = null;
public static string DatabaseConnectionString;
public static int NumberOfConnections;
public static int TotalConnectionsServiced;
public static DateTime DateStarted;
public static int FailedLoginAttempts;
public static int SuccessfulLoginAttempts;
public static string ErrorLogFile;
public static int TotalPagesServed;
public static Hashtable SessionTable;
public static Hashtable SessionTableSync;

public Global()
{
InitializeComponent();

DatabaseConnectionString=(string ) System.Configuration.ConfigurationSettings.AppSett ings["DBNameAndPath"];
NumberOfConnections=0;
TotalConnectionsServiced=0;
FailedLoginAttempts=0;
SuccessfulLoginAttempts=0;
ErrorLogFile=(string ) System.Configuration.ConfigurationSettings.AppSett ings["ErrorLogFile"];
TotalPagesServed=0;
DateStarted=System.DateTime.Now;
Hashtable SessionTable = new Hashtable();
Hashtable SessionTableSync = Hashtable.Synchronized(SessionTable);


Code Snippit from login.aspx----------------------------------------------------------------------------

Session.Add("UserID",sUserid);
Session.Add("FullName",sFullname);
Global.SuccessfulLoginAttempts++;
//System.NullReferenceException on the next line
Global.SessionTableSync.Add(sUserid,Session.Sessio nID); //tried with .ToString() also

I'm not trying to be dense, but I do have more of a procedural background than OO.

Thanks in advance,

Nick
Sep 21 '07 #1
6 3541
kenobewan
4,871 Expert 4TB
What's the value of session.sessionID? The thing that you have to think of in this situation is, I've got a problem how can I debug it? 1st POC the line that throws the exception, then work backwards. HTH.
Sep 21 '07 #2
Plater
7,872 Expert 4TB
Did .net1.1 applications not have a Session object built in to use?
Sep 21 '07 #3
What's the value of session.sessionID? The thing that you have to think of in this situation is, I've got a problem how can I debug it? 1st POC the line that throws the exception, then work backwards. HTH.
Thanks for the advice. SessionID is an alphanumeric value. Both the key and value I'm trying to insert are alphanumeric actually. It seems like the login.aspx cannot find the Global.SessionTableSync hashtable. I am very confused because other items (int and string) are accessible using Global.variablename. What is POC?

-Nick
Sep 21 '07 #4
Did .net1.1 applications not have a Session object built in to use?
There is a Session Object in .Net 1.1.
Sep 21 '07 #5
Plater
7,872 Expert 4TB
So then I am confused, why do you appear to be implementing your own?
Sep 21 '07 #6
Gotcha, I want to store all active sessions and associated userids in a hashtable. When Session_End, I delete the key and userid value. Session_Start occurs before the login.aspx is posted back to the server.

-Nick
Sep 21 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Szymon Madejczyk | last post by:
example code: public class envtest { public static void Main() { System.Diagnostics.Process proc = System.Diagnostics.Process.GetCurrentProcess(); string env =...
9
by: Billy Patton | last post by:
First, I'm not a student looking for help. Although there's nothing wrong with studens looking for help here. I'm learning c++ move further away from the perl wars here at work (my version is...
6
by: Jules | last post by:
I have the following code which isn't working as I expect it to: --- #include <iostream> using namespace std; class mystring { public: mystring (const char * src) { /* ... */ }
0
by: todorov-fkt | last post by:
Hello, I have packed a few images into resources files and compiled those files into a resource dll. The dll has a static function that returns all of the images. When I try to use the function...
1
by: Wee Bubba | last post by:
i have a class. within the constructor for this class it tests if 2 session objects exist and if they dont it creates them. this is a one off deal. The session objects are both Hashtables. ...
15
by: GTi | last post by:
If I use: ArrayList TimeScale = new ArrayList(); TimeScale.Capacity = 1000; TimeScale="test 1" The last line trow me an error: Index was out of range. Must be non-negative and less than the...
31
by: Extremest | last post by:
I have a loop that is set to run as long as the arraylist is > 0. at the beginning of this loop I grab the first object and then remove it. I then go into another loop that checks to see if there...
5
by: evaristobo | last post by:
i'm a bit confused here, a pointer is something aiming to an object, but a static class is not an object, nevertheless i would like to have the possibility of doing something like handling an...
9
by: raylopez99 | last post by:
Hello all— I’m trying to get the below to work and cannot get the format right. It’s from this example: http://msdn.microsoft.com/en-us/library/8627sbea(VS.71).aspx What it is: I’m trying...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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
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...
0
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,...

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.