开发者

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开发者_C百科 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


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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜