[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 813
  • Last Modified:

Session is nothing after page load

I'm using the State Server in my web.config file. and have tried using the SQLServer also.

<sessionState mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;user id=myuser;password=mypassword" cookieless="false" timeout="10"/>


I notice that when i use the SQLServer my sessions are stored in the database ASPStateTempSessions.

Now my problem is when i assign a session a value it's stored and i can write it to the page, but when i do another page load the session is lost. i see on a trace that it's being written to the database and that i think my problem lies somewhere where with each page load the sessionid changes, i'm not entirely sure why i can't read the session after i load the page or move to another. i'm using the microsoft example and paste that code below.

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="webbdata.WebForm1" enableViewState="True" EnableSessionState="True"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
      <HEAD>
            <title>WebForm1</title>
            <meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
            <meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
            <meta content="JavaScript" name="vs_defaultClientScript">
            <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
      </HEAD>
      <body MS_POSITIONING="GridLayout">
            <SCRIPT runat="server">
  Sub Session_Add(sender As Object, e As EventArgs)
     Session("MySession") = text1.Value
     span1.InnerHtml = "Session data updated! <P> Your session contains: <font color=red>" + Session("MySession").ToString() + "</font>"
  End Sub

  Sub CheckSession(sender As Object, e As EventArgs)
  response.write(session("MySession"))
    If Session("MySession") is nothing Then
      span1.InnerHtml = "NOTHING, SESSION DATA LOST!"
    Else
      span1.InnerHtml = "Your session contains: <font color=red>" + Session("MySession").ToString() + "</font>"
    End If
  End Sub
            </SCRIPT>
            <form id="Form1" runat="server">
                  <input id="text1" type="text" name="text1" runat="server"> <input id="Submit1" type="submit" value="Add to Session State" name="Submit1" runat="server" OnServerClick="Session_Add">
                  <input id="Submit2" type="submit" value="View Session State" name="Submit2" runat="server" OnServerClick="CheckSession">
            </form>
            <hr SIZE="1">
            <font size="6"><span id="span1" runat="server"></font></SPAN>
      </body>
</HTML>
0
simmonsusa
Asked:
simmonsusa
  • 16
  • 12
  • +1
1 Solution
 
DotNetLover_BaanCommented:
Whats in your code behind ?   Do you have one ?
-Baan
0
 
simmonsusaAuthor Commented:
No there is no code behind, I'm using .net framwork 1.1 on a windows 2003 server machine and visual stuidio 2002
0
 
tovvenkiCommented:
Hi,
I think that when you say mode="StateServer" then you need to start the aspstate service in the PC. are you sure that this service is running in you PC. if not then go to command prompt and type
net start aspstate

Regards,
venki
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
simmonsusaAuthor Commented:
yes this service is started, as mentioned also, the SQLServer session is being saved into the database but when the page reloads for some reason the session doesn't live.
0
 
daffodilsCommented:
Here is your problem..

stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1

<sessionState mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;user id=myuser;password=mypassword" cookieless="false" timeout="10"/>

These two fields need your server IP address and not the default address 127.0.0.1 !

Also you can use either State Server OR SQL Server for storing Session.. not both at the same time..

Store Session in either State Server as follows (use server IP and the default port 42424)
<sessionState mode="StateServer" stateConnectionString="tcpip=<server IP>:42424" cookieless="false" timeout="10"/>

Or store Session in either SQL Server as
<sessionState mode="StateServer" sqlConnectionString="data source=<server IP>;user id=myuser;password=mypassword" cookieless="false" timeout="10"/>
0
 
simmonsusaAuthor Commented:
The mode should be either SQLServer or StateServer, I'm having problems with both. the ip address should be correct with the 127 cause it all resides on the same machine, but just to test it i did go ahead and put the machine ip address in there instead but still have the same problem.

Please help.
0
 
simmonsusaAuthor Commented:
Just to clarify when i click the Add session button i can read the session, but when i click the View session button it is lost.
0
 
daffodilsCommented:
Lets start with SQL Server first..

Run InstallSqlState.sql (installed by default in <Drive>:\systemroot\Microsoft.NET\Framework\version) on the computer running SQL Server that will store the session state. This creates a database called "ASPState" with new stored procedures and ASPStateTempApplications and ASPStateTempSessions tables in the TempDB database.

In the application's Web.config file, set mode=SQLServer and set the sqlConnectionString attribute.

For example --> If they are all on the same machine.. and you are using windows authentication, set connection string as :
sqlConnectionString="data source=localhost;Integrated Security=SSPI;Initial Catalog=northwind"

The sqlConnectionString value shoudl be similar to the connection string used when actually connecting to the server.
So first test if you can connect to the SQL server from code with the connection string and then place it in the Web.config.
0
 
simmonsusaAuthor Commented:
Thanks mate, but i have done that, and in my original question explained that looking in at the ASPState database and using profiler can see that my session has been saved, my problem is after i reload the page or using my example click the view session button, that it has been lost. Everytime i create a session it is being stored in SQL server, but why does it get lost when i try to access the session again.
0
 
daffodilsCommented:
I just tested your code as with the State Service running and the connection string as
<sessionState
            mode="StateServer"
            stateConnectionString="tcpip=127.0.0.1:42424"
            sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
            cookieless="false"
            timeout="20"
/>

And it works !
0
 
daffodilsCommented:
Even when I Click "View Session State".. I can see the data I added !
0
 
daffodilsCommented:
what is the Value for "Log on as" column for your ASP.NET State Service.. in the Services console?
0
 
simmonsusaAuthor Commented:
Yes it should work, are you using the same software .net ver 1.1 with IIS 6, honestly after reading microsoft it shouldn't be difficult, and what i have done should work, but i dont' understand why it doesn't, that's why i'm here.
0
 
simmonsusaAuthor Commented:
NT AUTHORITY\NetworkService
0
 
daffodilsCommented:
Ahh.. I am using .NET ver 1.1 , but with IIS 5.0 with Win2K Advanced Server ..
0
 
daffodilsCommented:
Hey, does it work for you "InProc" ?
The reason am asking this is.. maybe machine.config doesn't have SessionStateModule
Sounds really unlikely.. but just in case.
0
 
simmonsusaAuthor Commented:
No it doesn't, well it does if i turn cookieless to true, which i had been doing but crystal has a bug when using the active X print on a form using cookieless to true, so i need to be able to get this to work. where do i find the machin.config file?
0
 
daffodilsCommented:
C:\winnt\microsoft.net/framework/v1.1.4322/CONFIG
0
 
daffodilsCommented:
Check for these sections...

<section name="sessionState" type="System.Web.SessionState.SessionStateSectionHandler, System.Web, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowDefinition="MachineToApplication" />

<pages buffer="true" enableSessionState="true" enableViewState="true"
            enableViewStateMac="true" autoEventWireup="true" validateRequest="true" />

<sessionState
            mode="InProc"
            stateConnectionString="tcpip=127.0.0.1:42424"
            stateNetworkTimeout="10"
            sqlConnectionString="data source=127.0.0.1;Integrated Security=SSPI"
            cookieless="false"
            timeout="20"
        />

<httpModules>
            <add name="Session" type="System.Web.SessionState.SessionStateModule" />

Although, it should have given an error if Session State was not enabled !
This is really wierd.. what's so different with IIS6.0 and Win2003 !!
0
 
simmonsusaAuthor Commented:
thanks, seems to look ok to me.
0
 
daffodilsCommented:
sorry.. I am out of ideas !
It should at least work "InProc" with EnableSessionState=true in the @Page directive !
0
 
simmonsusaAuthor Commented:
ok, well now i'm really stumped. i thought you know, it can't be the server because the server is storing the session and i can see that using the profiler, i thought i'd go to another machine and try it, and well there you have it, it's my browser. but i've enabled everything so for some reason on my browser it won't accept the cookie.
0
 
daffodilsCommented:
Oh.. so JavaScript is not enabled on your browser.. hmm, I think it is some security setting that turns it back on.
let me see..
0
 
daffodilsCommented:
Try this.. IE 6.0
Tools --> Internet Options  --> Security Tab --> Custom Level (Button)  --> Scroll to SCRIPTING section  --> Use Radio button select of Enable or Disable to turn Java Script support on or off
0
 
simmonsusaAuthor Commented:
I do have the active scription enabled but i still can't see it, i've tried on other win200 machines and xp machines and am having the same problem, the problem does not occur on NT machines for some reason, have you any ideas?
0
 
daffodilsCommented:
It is a classic Browser problem.. your security settings are giving you a problem.

what do you mean by this.. if you can't see it, how do you know it is enabled.
>>I do have the active scription enabled but i still can't see it,

Lets just set the security setting lower.. that should automatically set the Javascript on...
Tools --> Internet Options  --> Security Tab --> Custom Level (Button)  --> Reset Custom settings (drop down)  --> Set to Medium or Medium-Low or Low
0
 
daffodilsCommented:
One more thing to try.. off the top of my head.. do you have Virus Scan enabled? Try disabling that.

Here's an excerpt from an MSDN article

==When using the in-process session-state mode, session-state data is lost if aspnet_wp.exe or the application domain restarts. These restarts commonly occur in the following circumstances:
- Setting an attribute in the <processModel> element of the application's Web.config file that causes a new process to start when a condition is met, such as memoryLimit.
- The Global.asax or Web.config file is modified.
- Changes to the \Bin directory of the Web application.
- Antivirus software scans and modifies the Global.asax file, the Web.config file, or a file in the \Bin directory of the Web application.    

==If you enable Web garden mode in the <processModel> element of the application's Web.config file, do not use in-process session-state mode. Otherwise, random data loss can occur.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconsessionstate.asp
0
 
daffodilsCommented:
Look at these MSDN articles.. to set the security settings

How to Manage Cookies in Internet Explorer 6
http://support.microsoft.com/default.aspx?scid=kb;EN-US;283185

PRB: Session Data Is Lost When You Use ASP.NET InProc Session State Mode
http://support.microsoft.com/default.aspx?scid=kb;en-us;324772

0
 
simmonsusaAuthor Commented:
I appreciate you pointing me into the right direction the answer in my situation is

http://support.microsoft.com/default.aspx?scid=kb;en-us;316112&Product=ie600

PRB: Session Variables Do Not Persist Between Requests After You Install Internet Explorer Security Patch MS01-055

My sql server is name SQL_SERVER which also hosts the intranet. thanks for all your help, if you hadn't given me that last answer i wouldn't have found this so i'll give you the points. thanks again.
0
 
daffodilsCommented:
Oh Great ! Sure.. Thanks, am glad I could help :).
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 16
  • 12
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now