By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,264 Members | 1,767 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,264 IT Pros & Developers. It's quick & easy.

Problem with public static hashtable in C#

P: 77
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
Share this Question
Share on Google+
6 Replies


kenobewan
Expert 2.5K+
P: 4,871
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
Expert 5K+
P: 7,872
Did .net1.1 applications not have a Session object built in to use?
Sep 21 '07 #3

P: 77
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

P: 77
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
Expert 5K+
P: 7,872
So then I am confused, why do you appear to be implementing your own?
Sep 21 '07 #6

P: 77
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

Post your reply

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