ASP.NET C# Static Variables are global?

后端 未结 4 1517
执念已碎
执念已碎 2020-11-29 07:00

Today I released a small asp.net beta web application which allows internal staff to modify some product information. We started running into issues where users were overwri

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 07:21

    Yes, in ASP.NET a static fields lifetime is for the app domain (note that this differs a bit for generic types).

    I'd recommend using the server Session for storage of data you want to associate with an instance of a client browser session (user login). i.e.

    Session["_groupID"] = Convert.ToInt16(Request.QueryString["GroupID"]);
    

    you can retrieve it by doing:

    short groupID = Convert.ToInt16(Session["_groupID"]);
    

提交回复
热议问题