我有一个Sharepoint 2013应用程序,需要防止用户同时从不同位置登录。
寻找一个好的解决方案,我发现每次用户登录时给一个新的会话令牌是一个很好的解决方案。另外,我还必须使该用户的所有较旧令牌失效。
如何使用c#.Net做到这一点?
答案 0 :(得分:0)
尝试像在普通ASP.NET应用程序中那样进行操作,唯一的区别是使用从HttpModule开始的会话,而不是从global.asax开始的会话。
在您的情况下,请执行以下操作:
public class CustomSessionHttpModule : IHttpModule { public void Init(HttpApplication context) { IHttpModule httpModule = context.Modules.Get("Session"); var sessionModule = httpModule as SessionStateModule; if (sessionModule != null) { sessionModule.Start += OnSessionStart; } } public void Dispose() { } private void OnSessionStart(object sender, EventArgs e) { //Check if user has active session( in your storage) if yes then invalidate it or block new request } }
答案 1 :(得分:0)
我已经尝试了很多解决方案。我试图处理Sessions和Cookies都没有成功。
我的解决方案是使用某种验证方式,例如IP。 检查IP(如果用户IP已更改)后,程序会将用户重定向到以下页面:
[sharepointsite] / _ layouts / closeconnection.aspx?loginasanotheruser = true
此页面来自Sharepoint的较早版本,并在2013版本中隐藏。 它会强制用户再次登录。
这是一些代码示例:
if(currentIP != lastIP)
{
updateIP(currentIP);
Response.Write("<sharepointsite>/_layouts/closeconnection.aspx?loginasanotheruser=true");
}
我知道这不是最好的解决方案,但它是唯一对我有用的解决方案。