views:

104

answers:

2

We have a bug that we are trying to fix. It looks like one user can see another users data it they hit the same aspx page at the same time.

I was wondering: If we store data in a property on the master page, will all pages running at the same time see that data.

Have a master page:

public class MyMasterBase : System.Web.UI.MasterPage
{
    private int myInt;
}

Create reference to master page from the aspx page:

MyMasterBase master = Page.Master as MyMasterBase;

Two users then call the aspx page at the same time:

  • The first user sets myInt to 1
  • The second user sets myInt to 2
  • If the first user reads the myInt value what will it be?

I expect that it would be 1, but if it was 2 it would explain our bug :)

Thanks

Shiraz

+1  A: 

Sounds like a cache problem to me. MasterPages don't persist data between sessions, but the Cache will. Find everywhere in your project that you're putting information into the Cache and ensure no user or session-specific data is going into it. Cache should only hold information that applies to all users at a given time.

Sonny Boy
Thnaks for the answer, it turned out to be a problem with the way we were running a windows workflow
Shiraz Bhaiji
+1  A: 

That depends on what you do with myInt. If you store its value in Session check your users' identities (Page.User.Identity.Name), if they're equal you will read the latest set value. If you store it in ViewState each user will read his own value. if you don't persist it at all (i assume that is the case), the value will not be saved (reset on each request for each user). Probably what you want is something like this (just a guess):

int property MyInt {
    get { return Convert.ToInt32(ViewState["MyInt"]);}
    set { ViewState["MyInt"] = value; }
}
UserControl