SESSION VARIABLE NOT WORKING IN WEB SERVER

Rate It (1)

Last post 08-12-2007 5:36 AM by joteke. 6 replies.

Sort Posts:

  • Embarrassed [:$] SESSION VARIABLE NOT WORKING IN WEB SERVER

    08-07-2007, 4:03 AM
    • Loading...
    • shuvradip
    • Joined on 08-05-2006, 4:34 AM
    • kolkata
    • Posts 9

    i v stored some database driven values into session variables at the time of login(i.e user id,user name cetc..)..while running this website in localhost(iis)this works fine. but while i upload this in windows webserver without giving ne error it seems that session variables failed to store the data(after logging in while navigating through the website session variables become null).but the confusing thing is that somtimes itz working..

    sessionState mode is default for windows server

     please help


    following is the code

    string sSqlCmd = "SELECT eum_id, eum_uid, eum_pwd, eum_name, edm_name, eum_evm_id,eum_edm_id FROM ei_user_master,ei_dealer_master where eum_edm_id = " + ddlDealer.SelectedValue + " and eum_uid = '" + txtUser.Text + "' and eum_evm_id = " + cmbDept.SelectedValue + "";
            // Open the database
            conn.Open();
            OleDbDataReader dr;
            OleDbCommand cmd = new OleDbCommand(sSqlCmd, conn);
            dr = cmd.ExecuteReader();
            dr.Read();
            if (!dr.HasRows)
            {
                FailureText.Text = "invalid username/dealer of/dealer name";
                conn.Close();
            }
            else
            {
                if (dr["eum_pwd"].ToString() != txtPwd.Text)
                {
                    FailureText.Text = "invalid password";
                    conn.Close();
                }
                else
                {
                    try
                    {
                        Session["UidER"] = dr["eum_id"];
                        Session["UserName"] = dr["eum_name"];
                        Session["DealerName"] = dr["edm_name"];
                        Session["VehicleID"] = dr["eum_evm_id"];
                        Session["DealerID"] = dr["eum_edm_id"];
                        conn.Close();
                    }
                    catch (Exception ex)
                    {

                    }
                    finally
                    {
                        Response.Redirect("Configuration.aspx");
                    }

                }
            }

     please help

    Shuvradip Sengupta
    software developer
    xinis pvt ltd.,Kolkata
  • Re: SESSION VARIABLE NOT WORKING IN WEB SERVER

    08-07-2007, 7:22 AM
    • Loading...
    • SGWellens
    • Joined on 01-02-2007, 4:27 PM
    • MN, USA
    • Posts 3,084
    • Moderator
      TrustedFriends-MVPs

    If the windows "web server" you are uploading to is a web farm (collection of servers) you cannot use sessionState mode.  The first time a client hits the site, it may go to Server A and store the session variable.  The second time the client hits the site, it may go to Server B where it will not find the session variable.

    By the way, failing silently is not a good idea.  And, you should close the connection in the finally clause:

        catch (Exception ex)
        {
            // report something!
        }
        finally
        {
             conn.Close();
             Response.Redirect("Configuration.aspx");
        }
    
     

     

    Steve Wellens
  • Re: SESSION VARIABLE NOT WORKING IN WEB SERVER

    08-07-2007, 7:45 AM
    • Loading...
    • shuvradip
    • Joined on 08-05-2006, 4:34 AM
    • kolkata
    • Posts 9

    thanks sir 

    in the finally clause conn.close is der please tell me if that ll nt work .

    my sessionState mode is "inproc"(by default) and the web server is not distributed

     

    Shuvradip Sengupta
    software developer
    xinis pvt ltd.,Kolkata
  • Re: SESSION VARIABLE NOT WORKING IN WEB SERVER

    08-09-2007, 11:19 PM
    • Loading...
    • shu_chen4
    • Joined on 08-10-2007, 3:04 AM
    • Posts 1

    I have just recently started having the same problem.  Actually I'm not sure how long it's been happening, but users are starting to report the problem more frequently now.  It seems to be very sporadic and I cannot replicate it.  My website flow is pretty similar to yours.  I run a database query, present the results to the user, and the user selects one of the options.  The data is moved via query string to another page where they log in.  After login  a database row is created and the data is stored in the database.  The user gets back an id corresponding to the database row.  That id is stored into session variables.  Every now and again it appears that my session variables become null.  I have no idea what is causing the problem and the fact that I can't replicate makes it very difficult to troubleshoot.  I hope someone can shed some light!   

  • Re: SESSION VARIABLE NOT WORKING IN WEB SERVER

    08-11-2007, 3:22 PM

    asp worker process that handles aspx requests in InProc mode could be restarted to improve performance or due to system restart.

    You should use StateServer or SqlServer session management if you want to preserve session state.

     

    Gursharn Singh


    http://blogexception.blogspot.com


    [Don't forget to click on Mark As Answer on the post that helped you ]
  • Re: SESSION VARIABLE NOT WORKING IN WEB SERVER

    08-11-2007, 5:07 PM

    I am also having this same problem. Please post if anyone have any answer.

     

    Thanks

    jijo

  • Re: SESSION VARIABLE NOT WORKING IN WEB SERVER

    08-12-2007, 5:36 AM
    Answer
    • Loading...
    • joteke
    • Joined on 06-16-2002, 11:24 AM
    • Kyro, Finland
    • Posts 6,577
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs

    jijo_robert:

    I am also having this same problem. Please post if anyone have any answer.

     

    Thanks

    jijo

    Hi,

    as was stated on previous post. InProc session will be lost when AppDomain restarts occurs. Reason for that could be change in web.config, change of dlls in bin directory, virus scanner touching global.asax, application pool restarts (Windows Server 2003 / Vista), or application hangup whatever which forces it to be restarted. Therefore it's always more durable to keep the session in separate process (StateServer) or SQl Server. This way no restarts whatsoever interfere the sessions.

    More information about session state modes: http://msdn2.microsoft.com/en-us/library/ms178586.aspx

    Thanks,

    Teemu Keiski
    Finland, EU
Page 1 of 1 (7 items)
Microsoft Communities
Page view counter