Asp.net MVC Session

Hi Experts,

I have an asp.net MVC application that I have released to a test server online. On my dev machine it works fine, but online, I lose session after a few minutes.

can anyone tell me how to either persist my session variables until the end of the browser session, or if I should pass it out to a cookie.

I am dealing with extremely sensitive info ( medical records ) so security is of the essence.

Critto.
crittoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rdogmartinCommented:
Chances are your application domain is recycling. There are many reasons why this might happen - here is a good blog post about it.

One easy workaround is to use the ASP.NET State Service rather than the in-memory session. Configure the ASP.NET State Service to run automatically in the Services applet, then open web.config and update the <sessionState> element to  this:

<sessionState  mode="StateServer" stateConnectionString="tcpip=127.0.0.1"  cookieless="false" timeout="60"/>

Cheers,
Roger
0
crittoAuthor Commented:
Hey thanks for your post Roger. Just one question:

"Configure the ASP.NET State Service to run automatically in the Services applet."

How do I do this part??
0
jamesbaileCommented:
Either that or you are working in a load balanced environment and you are hitting different servers. If that is the case you will need to make sure you use a common state server.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

crittoAuthor Commented:
I'm being hosted on a commercial server, most probably a virtual machine. My utmost concern is security. I cant have any persisted information. What should I do in this case with my session persistence, without compromising 1. security, and 2. my session persistence.

Im playing with <sessionState mode="InProc" timeout="60" cookieless="UseUri" /> now to see if i can get around my session dying.

It is likely that I will need to persist over a clustered environment once I get past testing on my commercial host, so can you give me any tips on best practice that will work on both?
0
jamesbaileCommented:
If you can't store anything then does that mean that your application does not use a DB server?
0
crittoAuthor Commented:
Hi James, apologies.. No I mean't that just session info shouldn't be persisted to a client in any form that's all. I just realised I didn't mention this, but it's an asp.net mvc application. it's connected to an sql server 2008 database.
0
jamesbaileCommented:
If you use the the session state server then the only information that is stored in the client browser is the session id token. However any session data is stored server side by the state server including TempData if you are using the default TempDataProvider
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rdogmartinCommented:
To start the ASP.NET State Service, open the Services applet by typing services.msc in the Start bar or at the Start - Run prompt. Then look for the ASP.NET State Service in the list of services. Right click it and choose Properties. Change its startup type to Automatic and then manually start it.

The state service is compatible with a web farm as long as you point all the stateConnectionString values to the same server.
0
crittoAuthor Commented:
thanks guys, I'm going to use sql server for storing session state.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Frameworks

From novice to tech pro — start learning today.