Static variable in asp.net page

前端 未结 5 2050
无人共我
无人共我 2020-12-25 14:24

I am having one doubt regarding the use of static variable in Asp.net pages.

I am having one page say UserDetails.aspx. In this page, I have one static variable to s

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-25 14:55

    As Adeel already mentioned: static(or shared in VB.Net) variables are application-wide. That means they are the same for every user and exist till webserver is stopped or last session has abandoned.

    You could use the Session to store variables that belong to the current User.

    If you need access to other user's numberOfReviews(f.e. as administrator or for statistics), you could use database, asp.net-cache or a simple static dictionary with the userid as key.

提交回复
热议问题