5
votes

I am developing an asp.net website.

  • When two different users are accessing that website with different sessions, one users content is getting swapped to another user.
  • I am using javacsript, calling pagemethods from .aspx pages and C# at code behind.
  • This problem mainly occuring when two users are calling same functionality at a time.
  • I thought static variables could cause this problem and tried not to use any static variables or static functions except for pagemethod functions where it is manadatory for a pagemethod to be static.

please help me out with this problem.

7
Could you post an example of the code? - Damon
Is this site behind a load balancer? Is your session stored in process or in a database? - Facio Ratio
@Damon this is not related to a particular block of code.. this problem occurs in wherever a static variable is used. i tried to avoid static variables and static methods, but for pagemethods it is mandatory to have static function. still if u need sample code, i will provide it. - Hulk

7 Answers

5
votes

Could also be related to threading. Lock those variables up and see if that helps.

Static methods do not guarantee static variable state even though the methods are guaranteed to be thread-safe. You have to manage that state and asp.net treats static variables as shared amongst all users. See this answer from a related question.

More reading: Thread Synchronization

1
votes

We had a similar problem, and found that it was our loadbalancer(f5 Big-IP) that messed up the session-ids. We changed the loadbalancer to be stateful, and it now functions perfectly...

1
votes
  • turn on the aspnet state service in windows services.
  • use session["x"] instead of Static x
  • use viewstate["x"] for page level values
1
votes

Check your session state configuration (see example below). Perhaps you use another mode than "InProc" and running in some problems with that.

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

You could also consider using caching instances with keys that using the SessionID as prefix. The enterprise library offers a good caching implementation.

Hope this helps.

1
votes

remove you static variable and static method use to respond your request.

1
votes

Add sessionState in web.config:

<configuration>
  <system.web>
   <sessionState timeout="120" mode=" [InProc|StateServer|SQLServer|Custom]" cookieless="false"  />
  </system.web>
</configuration>

Try also the following solution:

  1. Start>Administrative Tools>Services
  2. right click on ASP.NET State Service and click 'start'.

Variables also need to LOCK as mentioned in @TombMedia's Answer.

This link may be help you: Exploring Session in ASP.NET

0
votes

this is to be set in Web.config and <%@ outputcache duration="1" varybyparam="none" %> this to be removed all the .aspx Forms..

Regards Rs