Shiraz Bhaiji
Shiraz Bhaiji

Reputation: 65411

State in ASP.net Master Page

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:

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

Thanks

Shiraz

Upvotes: 0

Views: 433

Answers (2)

UserControl
UserControl

Reputation: 15159

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; }
}

Upvotes: 1

Sonny Boy
Sonny Boy

Reputation: 8016

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.

Upvotes: 1

Related Questions