Solved

Session Variables die well before time set in web.config

Posted on 2008-10-09
12
541 Views
Last Modified: 2013-11-08
I store a userid in a session variable and 2 of my pages have updatepanels that refresh with an asp:timer, these pages, and a few without the timer, do not maintain the session variable and pass "NULL" when a commandbutton for DB update is passed.

I am fairly new to .NET (about a year) and never had this issue with classic ASP sessions.
<authentication mode="Forms">

      <forms timeout="60" cookieless="AutoDetect" loginUrl="default.aspx" defaultUrl="tb_main_menu.aspx" />

    </authentication>

      <sessionState cookieless="AutoDetect" timeout="60" />

Open in new window

0
Comment
Question by:cwickens
  • 6
  • 6
12 Comments
 
LVL 13

Expert Comment

by:copyPasteGhost
ID: 22682279
0
 
LVL 5

Author Comment

by:cwickens
ID: 22687929
It show (and all the examples show) use of a sqldatabaseconnection in the web.config.

Ok, that brings up another question, if I switch to stateServer mode, is this connection needed and if not, is this the connection to my app's DB or is there a default db used by the process?
0
 
LVL 5

Author Comment

by:cwickens
ID: 22687990
the other question, which may be the root cause, is: If I have a timer on the page (AJAXControlToolkit, asp:timer) and when the timer fires, the updatePanel on the page updates, does that count as an activity that will keep the session alive?
0
 
LVL 13

Expert Comment

by:copyPasteGhost
ID: 22688015
using the stateServer mode will solve your session dissapearing problem

for your dbv connection use this: in your web.config

<connectionStrings>
            <add name="DBConnection" connectionString="Data Source=SERVERIP;Network Library=DBMSSOCN;Initial Catalog=MYDBNAME;User ID=MYDBUSERNAME;Password=MYDBPASSWORD;"
        providerName="System.Data.SqlClient" />
      </connectionStrings>

then when you want to use this code in your C#: do this:

connString = ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString;
0
 
LVL 13

Accepted Solution

by:
copyPasteGhost earned 500 total points
ID: 22688073
0
 
LVL 5

Author Comment

by:cwickens
ID: 22688089
I gues I must be making this more difficult than I need to, but, is this a separate connection from the one I already have to my 'live' database?

Sorry for the braindead appearance of the question, however, I have been debugging this application after going to production and this is the only issue I have left to resolve...5 days and counting with about 3 hours of sleep a night, I am running on coffee at this point.  :)
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 13

Expert Comment

by:copyPasteGhost
ID: 22688124
if you already have a connection why are we trying to make a new one?

leave that code out. I thought you needed to know how to make a connection string in your web.config.....

I'm in the same situation! (Sleep Deprivation) Deadlines are fun!

Hope that clearifies things. If not ask away I'm here.
0
 
LVL 5

Author Comment

by:cwickens
ID: 22688262
ok, that helps, so just to bring it back around...

I can leave the session state in the web.config to default and include the jscript/aspx page from the link you sent and basically be done, right?
-OR-
If I use stateserver, I can leave out the reference to the sqldatabaseconnection in the web.config since the connectionstring is already defined like this:
<sessionState mode="StateServer"
      stateConnectionString="tcpip=SampleStateServer:42424"
      cookieless="false"
      timeout="20"/>
 
<bouncing head off keyboard> 9oo2erhkxaireuadofbi84adf98 </bouncing head off keyboard>
0
 
LVL 13

Expert Comment

by:copyPasteGhost
ID: 22688310
<sessionState mode="StateServer"
      stateConnectionString="tcpip=SampleStateServer:42424"
      cookieless="false"
      timeout="20"/>

this stores where the session state is stored.....not a connection to your database....you will need both. or you can lose the session state stuff...unless you need it. (I never include that)

Check here for more info about the session state:  
http://msdn.microsoft.com/en-us/library/system.web.configuration.sessionstatesection.stateconnectionstring.aspx

But besides that...you got it!
0
 
LVL 5

Author Closing Comment

by:cwickens
ID: 31504799
Thanks!
0
 
LVL 5

Author Comment

by:cwickens
ID: 22711581
I wanted to wait until today (after the holiday weekend) to see if there would be any issues with this.

I appear to have resolved this issue and even got 3 solid nights of sleep thanks to your assistance!

V/r,
chuck
0
 
LVL 13

Expert Comment

by:copyPasteGhost
ID: 22711593
you are welcome. thanks for the grade
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now