开发者

Logging out users authenticated in more than one location programmatically in Sharepoint 2010

I would like to know how to log out a user programmatically in Sharepoint if he or she tries to 开发者_StackOverflow中文版log in from another location.

Thank you.


By another location do you mean trying to login on 2 different devices?

So if I was signed in on my computer and then tried to login on my phone, the phone should not be able to login and should log the user out?

If this is correct then:

On user session start

  • if a user is already logged in, sign them out
  • store the login information (IPAddress) in a DB or Application state
if (System.Web.HttpContext.Current.Application[System.Web.HttpContext.Current.User.Identity.Name] != null)
{
    System.Web.HttpContext.Current.Response.Redirect("http://<server>/_layouts/SignOut.aspx");
}
else
{
    System.Web.HttpContext.Current.Application[System.Web.HttpContext.Current.User.Identity.Name] = System.Web.HttpContext.Current.Request.UserHostAddress;
}

On user session end

  • remove the login information (IPAddress) from DB or Application state
if (System.Web.HttpContext.Current.Application[System.Web.HttpContext.Current.User.Identity.Name] != null && System.Web.HttpContext.Current.Request.UserHostAddress != System.Web.HttpContext.Current.Application[System.Web.HttpContext.Current.User.Identity.Name])
{
    System.Web.HttpContext.Current.Application.Remove(System.Web.HttpContext.Current.User.Identity.Name);
} 

You could potentially see a problem if you have a long session timeout and try and login to another device before original session is destroyed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜