Content getting swapped for multiple sessions users in asp.net website
Asked Answered
S

7

5

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.

Salmonella answered 4/9, 2013 at 11:1 Comment(3)
Could you post an example of the code?Upright
Is this site behind a load balancer? Is your session stored in process or in a database?Hydrus
@Upright 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.Salmonella
C
5

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

Carr answered 13/9, 2013 at 6:30 Comment(3)
Locking the static variables/static functions is fine, but when n number of users accessing the same functionality, then this locking may cause website to be slow, right?Salmonella
The cost will in most cases be negligible, I've rarely encountered a scenario where I've had to go back and optimize. But when you do you start looking at thread syncronization its a whole new world. Lots of complicated fun stuff like Semaphores and Mutexes.Carr
Sorry for all the comments Hulk but this question is really the one you want to read, this one answers your question about speed - but the short answer is 50ns.Carr
T
1

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...

Teodoor answered 4/9, 2013 at 11:14 Comment(0)
J
1
  • turn on the aspnet state service in windows services.
  • use session["x"] instead of Static x
  • use viewstate["x"] for page level values
Jagged answered 16/9, 2013 at 15:5 Comment(0)
C
1

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.

Catling answered 16/9, 2013 at 15:51 Comment(0)
P
1

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

Peashooter answered 17/9, 2013 at 4:2 Comment(0)
T
1

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

Th answered 17/9, 2013 at 8:18 Comment(0)
R
0

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

Regards Rs

Rebbeccarebe answered 15/9, 2014 at 7:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.