4

In case someone else has same problem and got it solved, would appreciate share his solution:

Problem: I have website done in asp.net mvc3, the session expires often, between some seconds to max 5 minutes. In web.config I have set the timeout to 2880 min, I also set the sessionstate to stateserver. I also delete the timeouts to use the default ones, still problem:

<sessionState mode="StateServer"></sessionState>
<authentication mode="Forms">
   <forms loginUrl="~/Account/LogOn"/>
</authentication>

I made a sample website that only contains the login functions and some database interaction to simulate the environment, then i got a more stable timeout of 2 min 50 secs (tested 9 times), which still is not correct since I set 2880 min in the web.config.

Inside the code when user login, I create an AuthenticateTicket and save it to cookies, then in secured pages I checked for User.Identity and the controllers have the filter [Authorize], so when session expires I'm sent to login page.

On the same hosting server I have other older apps using .NET 3.5 web forms, and for them the session is ok, only for new mvc3 and mvc3 the session is expiring often. Thanks for any clue you can give.

1
  • Hosted in Arvixe servers Commented May 4, 2011 at 14:44

3 Answers 3

3

Final:

My specific problem was my hosting (Arvixe) has set a limit of 100 MB memory for each website. Using EF (and likely any ORM) increases memory usage due to complex queries mapped to the database, so my websites were using more than 100 MB, causing the application pool to restart due to the 100MB memory limitation, hence Session was reset.

Solutions:

  • Optmize your MVC website (see this post)
  • Use another way to keep the session, maybe by storing it in SQL database.
  • Upgrade to a Virtual or Dedicated Server

For my specific case, setting each website to use shared app pool solved the problem temporary, while I follow the post on 1st option to optimize my websites so I can go under Arvixe's limit of 100MB memory.

Sign up to request clarification or add additional context in comments.

1 Comment

At the end, I swicthed to Dedicated App Pool again, and keep session at server level using: <sessionState mode="StateServer"/> and <machineKey validationKey="your key" decryptionKey="key desc" validation="SHA1" decryption="AES"/>
2

I had a similar issue my session was stopping at around 30 seconds, this only happened on my development environment. I found my solution here: http://forum.winhost.com/showthread.php?t=9017

Try to add your a machine key to your website.

Comments

1

This can be a common problem when using shared hosting, for the following reasons:

You are sharing a server with other customers and the ASP.NET worker process is being restarted frequently.

Your host is using load balanced servers and you are visiting one server and then on a subsequent visit you are then hitting another server where there is no session data.

Best workarounds are:

1, If you have a SQL database with your host have a look at setting up the database for shared session state.

2, When writing code don't depend on values in the session for a long duration - always do a check first and if the object is not in session then rebuild the object.

3, Consider moving to a VPS or upgrading your plan.

2 Comments

Thanks, I will ask that to my hosting, and inform here if solved the problem or not.
It looks the problem is this %....$ hosting company has set an unrealistic Memory limit of 100 MB, which, if you use EF, it is easily reached, causing app pool to restar, hence session lost. I yet to confirm but can check this ASP.NET MVC and EF Code First Memory Usage

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.