如何管理不同用户的会话? [英] How to manage session for different users?

查看:98
本文介绍了如何管理不同用户的会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在IIS上发布了该站点.
当用户登录到应用程序并开始输入数据时,应根据用户的需要维护数据,并且其他用户看不见数据.
当他们单击保存按钮时,不同用户的数据将合并到网格中.

例如:User1在网格中添加了一行.
当其他用户将其行添加到网格时,User1的网格中有四行.所有用户的sessionID都不相同.

我不明白为什么要合并数据.

如何为不同用户管理数据?

请帮助,我是ASP.Net的新手.

I have published the site on IIS.
As the users login into the application and start entering the data the data should be maintained user wise and not be visible to other users.
As they click the save button the data of the different users gets combined into the grid.

For example: User1 added a row to the grid.
As the other users add their rows to the grid User1 has Four rows in his grid. The sessionID is different for all the users.

I am not able to understand why the data is merging.

How can I manage data for different users?

Please help, I am new to ASP.Net.

//Class
public class DataTable
{
    public static DataTable dt;

    public DataTable()
    {
      dt = new DataTable();
      dt.Columns.Add("Col1");
      dtColumns.Add("Col2");

    }
}

//Web-Page

protected void btSave_Click()
{
   //Code to add data to datatable. 
   DataTable.dt.Rows.Add(DataRows);

   Session["DataTable"] = DataTable.dt; //  saving dataTable to session.

   Grid.DataSource = (DataTable)Session["DataTable"];
}

推荐答案

您是否在每个会话中都创建DataTable的新实例?

如果为true,为什么要在DataTable中使用静态成员?我认为您正在为每个用户使用相同的数据表.

尝试创建一个新的DataTable实例并禁用静态成员,它可以解决问题.

在此示例中,我更改了DataTable类的名称,因为它与原始DataTable相同.

例如:
Are you creating a new instance of DataTable in every session?

If true, why you''re using the static member in DataTable? I think that you''re using the same datatable for every user.

Try to create a new instance of DataTable and disable the static member, It can solve the problem.

For this example, I changed the name of DataTable class, because it''s the same that the original DataTable.

Ex:
//Classpublic
class MyDataTable
{
    public DataTable dt;
    public DataTable()
    {
        dt = new DataTable();
        dt.Columns.Add("Col1");
        dtColumns.Add("Col2");
    }
}

//Web-Page
protected void btSave_Click()
{   //Code to add data to datatable.
    MyDataTable dt = new MyDataTable();
    MyDataTable.dt.Rows.Add(DataRows);
    Session["DataTable"] = MyDataTable.dt;
    //  saving dataTable to session.
    Grid.DataSource = (DataTable)Session["DataTable"];
}


是的,您删除了
yes, you remove the
public static  DataTable  dt





to

public DataTable dt


这篇关于如何管理不同用户的会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆