使用会话ID删除会话时出现问题 [英] Problem in remove Session using session id

查看:76
本文介绍了使用会话ID删除会话时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hii,

我有一个问题,例如我想使用会话ID删除会话,但问题是它没有删除,所以它的ID一直呆在那里,所以我的代码无法正常工作

我的代码:

Hii,

I have one problem like i want to remove session using session id but problem is it''s not remove it''s id is stay there so my code is not working

MY CODE:

for (int i = 0; i < Repeater1.Items.Count; i++)
    {
        if    (((HtmlInputCheckBox)Repeater1.Items[i].FindControl("chk")).Checked)
        {
            string tempCompID = ((HtmlInputCheckBox)Repeater1.Items[i].FindControl("chk")).Value;
            Hashtable ht = (Hashtable)Application["SESSION_LIST"];//HERE i have get All session's list
                      ht.Remove(tempCompID);
            Session.Remove(tempCompID);
        }
    }


之后,我的总会话数减少了,但是我已在客户端浏览器中将其删除的该会话已在工作,因此我想使用会话ID在管理员端删除会话.
快点伙计们,我的工作卡住了...:(


after that my total session number is dcreased but that session which i have remove it''s in client browser working so i want to remove session at admin''s side using session id.
please hurry up guys my work is stucked...:(

推荐答案

我已经将您的问题解释为:-

您是管理员,想从管理面板终止其他用户的会话.

没有内置的机制可以访问其他用户的会话值.

在代码中执行
I have interpretted your question as:-

You are a admin and you wanted to terminate other user''s sessions from your admin panel.

There is no inbuilt mechanism to access other user''s session values.

In your code when you do
Session.Remove(tempCompID);

时,它实际上是从会话集合中删除会话,而不是从其他用户的会话中删除

我想到了三个选项来解决您的问题
1.我们可以通过将会话模式更改为SQLServer来解决此问题
并从相应的表中删除会话ID
因此,一旦您从会话表中删除了记录,那么用户将无法继续使用相同的会话ID

2.创建一个表,您可以在其中存储用户名和活动会话ID

在管理面板/表单中访问此表

删除条目/将条目标记为已删除的指定会话ID

在页面加载中,您始终可以检查该表中的值以获取特定的会话ID(如果不可用),然后执行

its actually removing the session from your session collection not from the other user''s

I thought of three options to resolve your issue
1.we can workaround on this by changing the Session Mode to SQLServer
and delete the session id from the corresponding tables
so once you delete the record from the session table then the user wont be able to continune using the same session id

2.Create a table where you can store the user name and the active session id

access this table in admin panel/form

delete the entry/mark the entry as deleted for a specified session id

in the page load you can always check the value from this table for the specific session id if it''s not available then do

Session.Abandon();

,以便当前用户会话将结束

3.创建一个应用程序级对象来存储登录用户ID,需要在global.asax中的Session_Start事件中设置Application["LoggedUsers"]值,然后在Session_End中将其删除,然后存储LoggedIn用户为List<sting>.我希望您已经在页面加载中验证会话,因此添加更多行以检查Application["LoggedUsers"]中是否存在用户ID(如果是),请继续,否则调用Session.Abandon();.现在最主要的是,在您的管理表单中,需要杀死所有用户会话,然后从Application["LoggedUsers"]中删除相应的用户.

将其标记为解决方案,如果解决了,您会发出

so the current users session will be ended

3.Create an Application level object to store the Logged In User Id, Application["LoggedUsers"] value needs to be set in Session_Start event in global.asax and remove them in Session_End, store the LoggedIn user as List<sting>. I hope you are already validating session in page load, so add on more line to check the user id is exist in Application["LoggedUsers"] if yes continue else call Session.Abandon(); . Now the main thing is that in your admin form which ever user''s session needs to be killed then remove the correpsonding user from the Application["LoggedUsers"].

mark it as solution, if it resolved you issue


此编码完成..

It''s done by this coding..

Hashtable ht = (Hashtable)HttpContext.Current.Application["SESSION_LIST"];
           IDictionaryEnumerator en = ht.GetEnumerator();
           HttpSessionState ss = HttpContext.Current.Session;
           if (HttpContext.Current.Session != null)
           {
               string sID = HttpContext.Current.Session.SessionID;
               if (ht.ContainsKey(sID))
               { }
               else
               {
                   HttpContext.Current.Response.ClearHeaders();
                   HttpContext.Current.Response.AppendHeader("Cache-Control", "no-cache"); //HTTP 1.1
                   HttpContext.Current.Response.AppendHeader("Cache-Control", "private"); // HTTP 1.1
                   HttpContext.Current.Response.AppendHeader("Cache-Control", "no-store"); // HTTP 1.1
                   HttpContext.Current.Response.AppendHeader("Cache-Control", "must-revalidate"); // HTTP 1.1
                   HttpContext.Current.Response.AppendHeader("Cache-Control", "max-stale=0"); // HTTP 1.1
                   HttpContext.Current.Response.AppendHeader("Cache-Control", "post-check=0"); // HTTP 1.1
                   HttpContext.Current.Response.AppendHeader("Cache-Control", "pre-check=0"); // HTTP 1.1
                   HttpContext.Current.Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.1
                   HttpContext.Current.Response.AppendHeader("Keep-Alive", "timeout=3, max=993"); // HTTP 1.1
                   HttpContext.Current.Response.AppendHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); // HTTP
                   HttpContext.Current.Response.Cookies.Clear();
                   HttpContext.Current.Response.Cookies["f758


jfp"].Expires = DateTime.Now; HttpContext.Current.Response.Cookies ["f758
jfp"].Expires = DateTime.Now; HttpContext.Current.Response.Cookies["f758


这篇关于使用会话ID删除会话时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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