473,836 Members | 1,393 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with public static hashtable in C#

77 New Member
am using Visual Studio 2003, .Net Framework 1.1, C#. I get a SystemNullRefer enceException when trying to do a hashtable.add(s tring,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.Http Application
{

private System.Componen tModel.IContain er components = null;
public static string DatabaseConnect ionString;
public static int NumberOfConnect ions;
public static int TotalConnection sServiced;
public static DateTime DateStarted;
public static int FailedLoginAtte mpts;
public static int SuccessfulLogin Attempts;
public static string ErrorLogFile;
public static int TotalPagesServe d;
public static Hashtable SessionTable;
public static Hashtable SessionTableSyn c;

public Global()
{
InitializeCompo nent();

DatabaseConnect ionString=(stri ng ) System.Configur ation.Configura tionSettings.Ap pSettings["DBNameAndP ath"];
NumberOfConnect ions=0;
TotalConnection sServiced=0;
FailedLoginAtte mpts=0;
SuccessfulLogin Attempts=0;
ErrorLogFile=(s tring ) System.Configur ation.Configura tionSettings.Ap pSettings["ErrorLogFi le"];
TotalPagesServe d=0;
DateStarted=Sys tem.DateTime.No w;
Hashtable SessionTable = new Hashtable();
Hashtable SessionTableSyn c = Hashtable.Synch ronized(Session Table);


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

Session.Add("Us erID",sUserid);
Session.Add("Fu llName",sFullna me);
Global.Successf ulLoginAttempts ++;
//System.NullRefe renceException on the next line
Global.SessionT ableSync.Add(sU serid,Session.S essionID); //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 3580
kenobewan
4,871 Recognized Expert Specialist
What's the value of session.session ID? 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 Recognized Expert Expert
Did .net1.1 applications not have a Session object built in to use?
Sep 21 '07 #3
stoogots2
77 New Member
What's the value of session.session ID? 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.SessionT ableSync hashtable. I am very confused because other items (int and string) are accessible using Global.variable name. What is POC?

-Nick
Sep 21 '07 #4
stoogots2
77 New Member
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 Recognized Expert Expert
So then I am confused, why do you appear to be implementing your own?
Sep 21 '07 #6
stoogots2
77 New Member
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
6657
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 = proc.StartInfo.EnvironmentVariables; }
9
2842
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 better, use it only) I've had this HashTable written in c that I've used for 10+ years. It works without any problems. I'm trying to reduce my overall amount of code by using STL in c++. To make migration easier I've create a class that inherits...
6
2005
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
1229
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 in an application I get the following exception (in translation from German): "A not handled exception of type 'System.Resources.MissingManifestResourceException' occured in mscorlib.dll
1
1598
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. afterwards the class is reinstantiated on a different page. i am then calling a method on this class. I basically want to retrieve one of the Hashtables from the session, clear it, then add a key/value to it. But for some reason i cant understand it is...
15
1715
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 size of the collection. Parameter name: index
31
4613
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 are more objects that match the first object that i grabbed. If they match then I put them in an array. I would like to remove each match from the arraylist as I find them to speed things up and so that they don't get checked again. If I try...
5
2775
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 HashTable and getting from it a pointer to a static class : ( (classStatic)myHash("classStatic") ).staticMethod() ....is this possible, or i'm i short on reading?
9
3121
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 to store multicast delegates in a hash table, and then fire the delegates one of two ways (after registering/ creating the delegates, etc).
0
9671
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
10845
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
9376
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
7792
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
5650
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5828
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4456
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4019
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3116
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.