|
|
如何同一时间一个帐号只有一个用户使用?(asp.net) |
|
|
作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站 |
用户真是变态,为了安全,已经设置了网卡绑定、IP绑定、HTTPS,他还要求一个帐号只能由一个人使用。总不成我在每个页面去判定是否已经由其他人使用了他的帐号吧! 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(); 
|
|
相关文章:相关软件: |
|