asp.net判断用户是否重复登录
2016-01-27 16:18
771 查看
登录页(Login.aspx.cs):
byte[] buffer = Guid.NewGuid().ToByteArray(); Session["Guid"] = 用户名 + BitConverter.ToInt64(buffer, 0).ToString() + " "; Application["online"] += Session["Guid"].ToString(); if (Application["online"].ToString().IndexOf(用户名) != Application["online"].ToString().LastIndexOf(用户名))</span> { string[] guidArray = Application["online"].ToString().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); string guid = ""; for (int i = 0; i < guidArray.Length; i++) { if (guidArray[i].ToString().IndexOf(用户名) == -1) { guid += guidArray[i] + " "; } } Application["online"] = guid + Session["Guid"]; }统一框架页或者各个页面:
<script type="text/javascript"> var ol; function online() { var xmlhttp; if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } else { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { if (xmlhttp.responseText == "0") { clearInterval(ol); alert("你的帐号已在别处登陆,你被强迫下线!"); window.location.href = "Login.aspx"; } else { clearInterval(ol); ol = setInterval(online, 3000); } } } xmlhttp.open("GET", "/online.ashx", true); xmlhttp.send(); } window.onload = function () { online(); } </script>online.ashx:
if (context.Application["online"].ToString().IndexOf(context.Session["Guid"].ToString()) == -1) context.Response.Write("0");
相关文章推荐
- ASP.NET 5简介
- ASP.NET 5 为NPM,BOWER设置代理服务器
- ASP.NET MVC FileResult的本质
- gridView中合并单元格
- 如何在ASP.Net中实现RSA加密
- asp.net MVC之创建自定义路由约束
- asp.net页面生命周期
- ASP.Net WebAPI的返回值
- ASP.Net运行原理与运行机制
- ASP.NET中一般处理程序报的错误:由于代码已经过优化或者本机框架位于调用堆栈之上,无法计算表达式的值
- Raspberry Pi手把手教你在树莓派上安装USB无线网卡支持WIFI
- aspx在页面跳转(Response.Redirect)时丢失session问题及解决办法
- Aspose Word 导入
- casperjs 各控件实现方法
- ASP.NET使用WebMethod
- ASP.NET使用Ajax总结
- ASP.NET前后台互相访问
- casperjs jsファイルサンプル1
- CASPERJSのbatファイル実行方法
- MVC aspx