今天我发布了一个小asp.net测试Web应用程序,它允许内部人员修改了一些产品信息。 我们开始运行到哪里使用者覆盖其他产品信息......尽管每个工作人员在编一个完全不同的行(产品)的问题。
在谷歌经过一番搜索,我想我知道是怎么回事,它做的使用静态变量,以下是问题的一个快速粗略的例子:
// EditProductGroup.aspx.cs
public partial class EditProductGroup : System.Web.UI.Page
{
private static int _groupId = 0;
protected void Page_Load(object sender, EventArgs e)
{
_groupId = Convert.ToInt16(Request.QueryString["GroupID"]);
// get existing ProductGroup information from database using
//_groupId to find the row and populate textboxes
}
private void saveProductGroupData()
{
// when user hits 'save changes' button, update row
//where the primary key column 'ProductGroupID' matches _groupId in the table
}
}
因此,根据我的研究,一个静态变量实际存在的应用程序作为一个整体,这意味着,如果多个用户使用,他们将有效地全部读取相同的“价值”为“_groupId”在某些情况下的应用程序实际上设置它为不同的值造成另一个用户页面的“实例”将数据保存到错误的行(ProductGroupId)。
我的目的是,静态变量是从其他用户隔离,并且不应该intefere - 每个用户都有自己的页面从而自己的“_groupId”变量的实例的实例。
幸运的是,这是一个开发/临时数据库不能实时数据库上的所有发生。 我不知道我是否只需要下车的“静态”关键字阻止变量被设置/每个人都读。
有什么想法吗? 谢谢