locked
Disappearing session state on published website RRS feed

  • Question

  • User-1694925868 posted

    I'm having problems with the sessions states on my application.

    When I run the application off my c drive all the session variables are there.  Everything works perfectly, nothing is wrong.

    However, when I publish the site to a server test environment, the session variables disappear.  Why is this?  Is there a way around this?

    Here is my codes.

    for retrieving it.  Note, the session.count actually is 0.

                if (Session.Count != 0)
                {
                    try
                    {
    
                        ddlidxSelection.Text = (string)Session["idx"];
                        DisplayLabelValues();
                        SetTextBoxes();
                        Button1.Enabled = true;
                        enablecontrolitems();
                        btnCommitInsertion.Visible = false;
                        SetTextBoxes();
                        Session.Remove("idx");
    
                    }
                    catch
                    {
                        string myErrorMessage = lblTest.Text;
                        lblTest.Text = "Session Failure" + myErrorMessage;
                    }
                }

     

    for setting the session variables.

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int mySelectedItem = this.GridView1.SelectedIndex;
            string myValue = GridView1.Rows[mySelectedItem].Cells[4].Text;
            Session["idx"] = GridView1.Rows[mySelectedItem].Cells[4].Text;
            Response.Redirect("ConfigurationAdminEmailListUPDATE.aspx");
        }
    Wednesday, March 9, 2011 5:16 PM

Answers

All replies

  • User-1583970805 posted

    Hi,

    Please check your web.config file for session enabled or not.

    Regards,

    Mansoor

    Thursday, March 10, 2011 2:40 AM
  • User-1856974186 posted

    Does any part of your application update web.config (eg application settings in appConfig)? If so then the app restarts so session state is lost. You can get around that by using configSource and externalising the configuration.

    Thursday, March 10, 2011 4:22 AM
  • User-1694925868 posted

    I'm lost as soon as I open my web.config file.

    Here is my web.config.  What am I looking for?

     

    <?xml version="1.0"?>
    <configuration>
    	<configSections>
    		<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    			<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    				<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
    				<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    					<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
    					<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
    					<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
    					<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
    				</sectionGroup>
    			</sectionGroup>
    		</sectionGroup>
    	</configSections>
    	<appSettings/>
    	<connectionStrings>
      <add name="NTS_AIMSConnectionString" connectionString="Data Source=AQUINAS;Initial Catalog=NTS_AIMS;Persist Security Info=True;User ID=cams_reports;Password=loon2008"
       providerName="System.Data.SqlClient" />
      <add name="NTS_AIMS_TestConnectionString" connectionString="Data Source=AQUINAS;Initial Catalog=NTS_AIMS_Test;User ID=cams_reports"
       providerName="System.Data.SqlClient" />
      <add name="NTS_AIMS_TestConnectionString2" connectionString="Data Source=AQUINAS;Initial Catalog=NTS_AIMS_Test;Persist Security Info=True;User ID=cams_reports;Password=loon2008"
       providerName="System.Data.SqlClient" />
      <add name="FacultyConnectionString1" connectionString="Data Source=AQUINAS;Initial Catalog=NTS_AIMS_Test;Persist Security Info=True;User ID=cams_reports;Password=loon2008"
       providerName="System.Data.SqlClient" />
      <add name="ConfigurationAdminEmailList" connectionString="Data Source=AQUINAS;Initial Catalog=NTS_AIMS_Test;Persist Security Info=True;User ID=cams_reports;Password=loon2008"
       providerName="System.Data.SqlClient" />
      <add name="NTS_AIMS_TestConfigurationAdminEmailList" connectionString="Data Source=AQUINAS;Initial Catalog=NTS_AIMS_Test;Persist Security Info=True;User ID=cams_reports;Password=loon2008"
       providerName="System.Data.SqlClient" />
      <add name="NTS_AIMS_ConnectionString" connectionString="Data Source=AQUINAS;Initial Catalog=NTS_AIMS_Test;Persist Security Info=True;User ID=cams_reports;Password=loon2008"
       providerName="System.Data.SqlClient" />
     </connectionStrings>
    	<system.web>
    		<compilation debug="true">
    			<assemblies>
    				<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
    				<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    				<add assembly="System.Web.Extensions.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    				<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    				<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    				<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    				<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    				<add assembly="System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/></assemblies>
    		</compilation>
    		<authentication mode="Windows"/>
    		<pages>
    			<controls>
    				<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    				<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    			</controls>
    		</pages>
    		<httpHandlers>
    			<remove verb="*" path="*.asmx"/>
    			<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    			<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    			<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
    		</httpHandlers>
    		<httpModules>
    			<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    		</httpModules>
        <trust level="Full"/>
    	</system.web>
    	<system.codedom>
    		<compilers>
    			<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    				<providerOption name="CompilerVersion" value="v3.5"/>
    				<providerOption name="WarnAsError" value="false"/>
    			</compiler>
    			<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    				<providerOption name="CompilerVersion" value="v3.5"/>
    				<providerOption name="OptionInfer" value="true"/>
    				<providerOption name="WarnAsError" value="false"/>
    			</compiler>
    		</compilers>
    	</system.codedom>
    	<system.webServer>
    		<validation validateIntegratedModeConfiguration="false"/>
    		<modules>
    			<remove name="ScriptModule"/>
    			<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    		</modules>
    		<handlers>
    			<remove name="WebServiceHandlerFactory-Integrated"/>
    			<remove name="ScriptHandlerFactory"/>
    			<remove name="ScriptHandlerFactoryAppServices"/>
    			<remove name="ScriptResource"/>
    			<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    			<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    			<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    		</handlers>
    	</system.webServer>
    	<runtime>
    		<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    			<dependentAssembly>
    				<assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
    				<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
    			</dependentAssembly>
    			<dependentAssembly>
    				<assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
    				<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
    			</dependentAssembly>
    		</assemblyBinding>
    	</runtime>
    </configuration>
    Thursday, March 10, 2011 12:19 PM
  • User-481631678 posted

    Your web.config do not have a entry for Session. You need to put this line right after opening tag of <system.web>.

     

    <sessionState mode="InProc" cookieless="false" timeout="20" />

    Friday, March 11, 2011 9:06 AM
  • User-660870441 posted

    Hi,<o:p></o:p>

    Session lose due to many reasons. Please refer to Common reasons for the session loss issue in ASP.NET applications and try to resolve the issue.<o:p></o:p>

    If it does not help resolve the issue, while in process session is a bit unstable according to the reasons in that article, I would suggest you try out-of-process session state. Please see Session-State Modes for more information.  And also please explicitly configure the machine key when out-of-process session state is used. Please see machineKey Element (ASP.NET Settings Schema).<o:p></o:p>

    Thanks,<o:p></o:p>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 14, 2011 3:45 AM