asp.net有個eventhandle是PreRequestHandlerExecute,好了,我們就在這個事件裡面判使用者是否已經被其他人登入了,如果是,則轉向到提示頁面吧。
//目前Session是否存在
if(System.Web.HttpContext.Current.Session!=null)
{
//使用者是否登入
if(System.Web.HttpContext.Current.Session["UserId"]!=null)
{
//擷取使用者登入的SessionID,在登入頁面設定,并判定兩個ID是否是相同的,不同嘛則後來有人用你的帳号登入了。
if(Application["Session"+System.Web.HttpContext.Current.Session["UserId"].ToString()].ToString() !=System.Web.HttpContext.Current.Session.SessionID)
{
Response.Redirect("/otheroneLogin.html",true);
}
}
}
//在初始化Global中Hook
public Global()
{
this.PreRequestHandlerExecute += new System.EventHandler(this.Global_PreRequestHandlerExecute);
}
//登入時設定的代碼
Application.Lock();
Application["Session"+Session["UserId"].ToString()]=Session.SessionID;
Application.UnLock();