Weird... Session[] not working from static classes (IIS only problem)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Benton

    Weird... Session[] not working from static classes (IIS only problem)

    Hi there,

    I'm having a problem with a method which resides on a static class I have on
    my ASP.NET application.

    public static string FilterCenter(st ring fieldName)
    {

    string centers =
    ((User)System.W eb.HttpContext. Current.Session["userdata"]).Centers;

    ...some more code...
    }

    The point here is how I cast Session["userdata"] to the (User) type so I can
    access the Centers property. This method works fine on my development
    machine with the VS 2005 web server.

    However, after deploying to the Windows 2003 server, I get this exception:

    [NullReferenceEx ception: Object reference not set to an instance of an
    object.]

    That is, it seems that Session["userdata"] is now null. Again, this only
    happens on the production IIS server.

    So... am I doing something wrong here trying to access Session[] from a
    static class? If not, why does it work on VS 2005 but fails on IIS 6?

    Thanks in advance,

    -Benton



  • Mark Rae

    #2
    Re: Weird... Session[] not working from static classes (IIS only problem)

    "Benton" <conversar@gmai l.comwrote in message
    news:51n3elF1kv tokU1@mid.indiv idual.net...
    I'm having a problem with a method which resides on a static class I have
    on my ASP.NET application.
    You have to be *really* careful with static classes in ASP.NET:

    The point here is how I cast Session["userdata"] to the (User) type so I
    can access the Centers property. This method works fine on my development
    machine with the VS 2005 web server.
    Ah yes, but you're the only person connected to it, so the fact that you're
    using statics doesn't matter... :-)


    Comment

    • bruce barker

      #3
      Re: Weird... Session[] not working from static classes (IIS onlyproblem)

      either session is disabled on the server or the server is recycling. if
      you use inproc sessions, you should always check for null, and have
      recovery code.

      -- bruce (sqlwork.com)

      Benton wrote:
      Hi there,
      >
      I'm having a problem with a method which resides on a static class I
      have on my ASP.NET application.
      >
      public static string FilterCenter(st ring fieldName)
      {
      >
      string centers =
      ((User)System.W eb.HttpContext. Current.Session["userdata"]).Centers;
      >
      ...some more code...
      }
      >
      The point here is how I cast Session["userdata"] to the (User) type so I
      can access the Centers property. This method works fine on my
      development machine with the VS 2005 web server.
      >
      However, after deploying to the Windows 2003 server, I get this exception:
      >
      [NullReferenceEx ception: Object reference not set to an instance of an
      object.]
      >
      That is, it seems that Session["userdata"] is now null. Again, this only
      happens on the production IIS server.
      >
      So... am I doing something wrong here trying to access Session[] from a
      static class? If not, why does it work on VS 2005 but fails on IIS 6?
      >
      Thanks in advance,
      >
      -Benton
      >
      >
      >

      Comment

      • Benton

        #4
        Re: Weird... Session[] not working from static classes (IIS only problem)

        either session is disabled on the server or the server is recycling. if
        you use inproc sessions, you should always check for null, and have
        recovery code.
        >
        -- bruce (sqlwork.com)
        Thanks for the advice. I've overcome this using a different approach. Any
        clues why it works on VS 2005 intregrated web server but fails on IIS 6?
        Same project, same web.config

        Cheers,

        -Benton

        Comment

        Working...