asp.net multi-user login data random string

Used to the C / S programming, often define a global variable, for convenience, and the next call to a function of time can still get to the value of the variable, we often define the static type of global variables.
 
  But now programmed turn on B / S, the bad habits come naturally follow over. Each time login page, the user's basic information of all global variable definitions become static type. As a result, we discovered a serious problem. Joe Smith user is logged in, it displays the basic information of Joe Smith, Joe Smith and then add a user record. As usual, said the display of the list is Joe Smith finished adding the record, the result of information listed is John Doe. This is a horse of God.
 
  The reason is that static variables out of the ghost, because after a user logs on Joe Smith, John Doe once logged in, this time value on the server static variable is reassigned, rather than the name of Joe Smith, not John Doe to replace. In this way, after Joe Smith added information, display their data in the database to the list when Joe Smith. John Doe's information comes naturally displayed. This may seem very strange, in fact, implies problems of asp.net operating mechanism.
 
  asp.net, all users use the same value of a static variable, this often applies to the record number of people visited the historical site. Every time one more person access, the value of static variable is incremented. Site history all users who value displayed changes also followed. But it must not be used to record user login global variables, otherwise there will be problems described above. Little Murder global variable implies a large potential data leakage.
 
  If you want to achieve B / S for the client end user's page-level global variables that how to achieve it? Fortunately, in addition to the traditional Asp Session object, it provides a better Asp.net ViewState object. ViewState object is used to store various variable page, and even objects. Why can ViewState rather than using static variables which? The reason is that the server will create a ViewState for each user to connect to the page, respectively, equivalent to the page level so ViewState Session. This time we can safely use ViewState need to access variables and objects of the staging. However, if you want to use ViewState, there must be a server-side form tag (<form runat = server>) in ASPX page.

Guess you like

Origin www.cnblogs.com/zyh-C/p/10978997.html