ASP.NET杀会议通过标识 [英] ASP.NET Kill Session By Id

查看:77
本文介绍了ASP.NET杀会议通过标识的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有用户权限的控制,因为并不是所有的用户都可以访问完整的网站。这时,对于特定用户的所有这些权限都存储在他的会议,因为这将是一个问题,我在数据库搜索每一个岗位上一步。

问题是,当我删除权限,用户仍然可以访问该页面,只有当他关闭浏览器更新生效。

有没有办法杀了ID的特定应用程序会话,迫使用户重新登录?


解决方案

 有没有办法杀了ID的特定应用程序会话,迫使用户重新登录?

没有。你只能访问用户的做着当前请求的Session对象(即自己),而不是其他用户会话对象。

所以,你需要存储用户的其他地方的标识,例如在静态集合。当用户的下一个请求,你可以检查id是集合中,并更新许可或注销用户。

另一个方法是保持的所有当前登录的权限对象在用户的静态集合以及在其会话变量。这样,你就能够改变的权限对象,而无需访问该用户的会话对象。

当然,在Web应用程序中使用静态变量来跟平时precautions。因为多个线程可以访问它,访问已被synchonised。此外,作为阿列克谢Levenkov指出的那样,如果你有多个服务器,你必须保持服务器之间synchonised的数据。

My application has a control of User Permissions, because not all users can access full website. At this moment, all those permissions for an specific user are stored in his session, 'cause It would be a problem for me to search at Database every Post Back.

The problem is that when I remove a permission, user can still access the page, and only when he closes the browser, the update take effect.

Is there a way to Kill an specific Application Session by the ID, forcing user to Log in again?

解决方案

"Is there a way to Kill an specific Application Session by the ID, forcing user to Log in again?"

No. You can only access the Session object of the user doing the current request (i.e. yourself), not other users Session objects.

So, you need to store the id of the user somewhere else, for example in a static collection. When the user makes the next request you can check if the id is in the collection, and update the permissions or log out the user.

Another alternative would be to keep the permission objects of all currently logged in users in a static collection as well as in their Session variable. That way you would be able to change the permission object without accessing the Session object of that user.

Using static variables in a web application of course comes with the usual precautions. As multiple threads can access it, the access has to be synchonised. Also, as Alexei Levenkov pointed out, if you have multiple servers you have to keep the data synchonised between the servers.

这篇关于ASP.NET杀会议通过标识的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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