Problem with public static hashtable in C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stoogots2
    New Member
    • Sep 2007
    • 77

    Problem with public static hashtable in C#

    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
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    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.

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      Did .net1.1 applications not have a Session object built in to use?

      Comment

      • stoogots2
        New Member
        • Sep 2007
        • 77

        #4
        Originally posted by kenobewan
        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

        Comment

        • stoogots2
          New Member
          • Sep 2007
          • 77

          #5
          Originally posted by Plater
          Did .net1.1 applications not have a Session object built in to use?
          There is a Session Object in .Net 1.1.

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            So then I am confused, why do you appear to be implementing your own?

            Comment

            • stoogots2
              New Member
              • Sep 2007
              • 77

              #7
              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

              Comment

              Working...