用户之间共享相同的会话 [英] Same Session shared among the user

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

问题描述


我有一个奇怪的问题.
在网格视图中单击选定的行后,我在会话中初始化了一些值.
它工作正常.

但是,当两个或更多用户(*全部具有不同的计算机和不同的用户)单击网格视图的不同行时,所有会话的值将分配给其他用户.
例如,如果usser1和user2在同一时间单击gridview,那么user1的所有会话将分配给user2,这意味着user2现在拥有user1的所有凭据.

但是当我在会话初始化之前添加thread.sleep(500)时,它工作正常.

任何人都可以启发我如何停止会议共享的问题吗?

示例代码可帮助您更好地理解:

1)
类别:-

namespace ABC.ZXY
{
    [Serializable]
    public class Employee
    {
        public Employee();
        public Employee(EntAhsviresourcesRow row);
        public Employee(EntEgemAhsresourcesRow row);
        public AgressoAddress Address { get; set; }
        public string AparGrId { get; set; }
     }
}



2)
网格视图事件"SelectedIndexChanging"

protected void grvEmployeeSearch_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
   Employee resource = (Employee)grvEmployeeSearch.DataKeys[e.NewSelectedIndex].Value;
 	
	if (resource != null)
            {
                resource = ec.GetEmployeePositionsByEmployee(resource, Client);
                SelectedResource = resource;
                Session["Resource"] = resource;
		Response.Redirect("Resource.aspx");
            }
.
.
.
}


3)
在resource.aspx页上:

员工ResourceFromSearch

protected void Page_Load(object sender, EventArgs e)
        {
		ResourceFromSearch = (Employee)Session["Resource"];
	}



现在在Resource.aspx上,我们得到了无效的会话.(不仅是此会话,而且是所有会话)

问候

解决方案

如您所知,Session值应该是用户会话唯一的,因此,除非IIS安装程序完全搞砸了它,否则它必须具有与您管理会话的方式有关.不幸的是,您忘记发布任何代码来将信息实际添加到会话中,因此我无法对其进行查看,以查看是否有明显的内容.


看看下面的文章,它说明了如何处理会话.我认为会议确实没有重叠.很有可能是应用程序中的缓存.

会话状态提供程序 [

protected void grvEmployeeSearch_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
   Employee resource = (Employee)grvEmployeeSearch.DataKeys[e.NewSelectedIndex].Value;
 	
	if (resource != null)
            {
                resource = ec.GetEmployeePositionsByEmployee(resource, Client);
                SelectedResource = resource;
                Session["Resource"] = resource;
		Response.Redirect("Resource.aspx");
            }
.
.
.
}


3)
On resource.aspx page:

Employee ResourceFromSearch

protected void Page_Load(object sender, EventArgs e)
        {
		ResourceFromSearch = (Employee)Session["Resource"];
	}



Now on Resource.aspx we got invalid session.( Not only this session but all sessions)

Regards

解决方案

As you are aware, a Session value is supposed to be unique to the user session, so unless something is completely screwed up with the IIS setup, it has to be something to do with the way you are managing the Session. Unfortunately, you forgot to post any of your code for actually adding the information to the session, so I can''t take a look at it for you to see if there''s anything obvious.


Take a look a the following article, it explains how session is handled. I do not think session does overlap. Most possibly, it could be the cache in your application.

Session State Providers[^]

If this is not the case. Can you pleae add more details to your question.

Note: If you are implementing a custom session provider this may not be applicable.


Instead of sharing session values could you use application object to share / exchange information between two or more users


这篇关于用户之间共享相同的会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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