.Net session variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • arial
    New Member
    • Sep 2007
    • 109

    .Net session variable

    Hi all,

    I have problem with session variable on .net web form.

    I am saving ID in session to pull up the other .net web form it works fine with my development environment but as soon as I put my application in production environment but session varible doesn't work.

    this what I have in session:

    String getid = Session["qid"].ToString();

    and my "getid" comes null in production.

    It is very urgent I am suppossed to release this application and I got stuck with this problem.

    Please please can anyone explian me this situation?

    Thank you Thank You
  • Shashi Sadasivan
    Recognized Expert Top Contributor
    • Aug 2007
    • 1435

    #2
    Technically you should be typecasting the session tot a String type;

    String getid = (String)Session["qid"];

    moreover if getid is being thrown at null,
    then Session["qid"] should be null, and Session["qid"].ToString should throw an exception

    The result you see may be IIS specific. Have you defined the session variables in global.asax ?

    Comment

    • kunal pawar
      Contributor
      • Oct 2007
      • 297

      #3
      First trace ur session set properly or not

      Comment

      • arial
        New Member
        • Sep 2007
        • 109

        #4
        I tried to dubugg and this is what i have found out.

        My session variable get to my another form which doesn't need this session variable but I am getting null in a webform where I need this session variable.
        for example this is what I have;

        Code:
        form1:
        
        session["qid"] = qid...............this one does gets the value of qid
        
        Form2: 
        
        string test = Session["qid"].ToString(); ...................test does gets value of qid
        
        form3:
        
        string getid = Session["qid"].ToString(); ..................getid is null here.
        It is just not making any sense to me.

        How would I initialize session variable in globas.aspx file?

        Comment

        • balabaster
          Recognized Expert Contributor
          • Mar 2007
          • 798

          #5
          How would I initialize session variable in globas.aspx file?
          I'm betting you don't have a global.asax file in your web application...

          In Solution Explorer, right click your application and click Add/New Item...
          Select a Global Application Class (the name will be Global.asax in the edit field at the bottom).
          Click Add

          In the Global.asax.cs file which comes up, in the Session_Start routine initiate your variables as such:

          session["Field1"] = "";
          session["Field2"] = "";
          //etc.

          When I've run across this problem in the past, that's usually what I've missed.

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            I don't think i've ever declared Session variables in the global.asx page.
            I suppose that would mean you don't need to check for null, just for empty strings.
            A lot of people seem to be having trouble with their Session objects lately and I can't reproduce any of their problems.

            Comment

            • balabaster
              Recognized Expert Contributor
              • Mar 2007
              • 798

              #7
              Originally posted by Plater
              I don't think i've ever declared Session variables in the global.asx page.
              I suppose that would mean you don't need to check for null, just for empty strings.
              A lot of people seem to be having trouble with their Session objects lately and I can't reproduce any of their problems.
              It's been a whlie since I used session objects, but when I had this issue in the past, that's exactly the way I've solved it.

              Comment

              • arial
                New Member
                • Sep 2007
                • 109

                #8
                Thank you all for your reply.

                I declare session to the global file so, now i am not getting an error message but it is not displaying the data.

                need more help on to resolve this.

                Thank you

                Comment

                • kunal pawar
                  Contributor
                  • Oct 2007
                  • 297

                  #9
                  check u allowed session for this page, coz there is property in @page to allow session. another thing check qid is empty / null

                  Comment

                  • arial
                    New Member
                    • Sep 2007
                    • 109

                    #10
                    Thanks Kunal,

                    I do have string qid = "";

                    and what property to check for allowing session at page?

                    Thank You

                    Comment

                    Working...