两个客户,在不同的机器登录同一个帐号的问题? 用session保存一个值 标识是否已登录然后判断这个值 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可用application或cache或static对象保存已经登录用户的id和ip信息等. 可以再具体一些吗? 给个example吧! 放在全局对象中 例如application cache用hash table保存 login.aspxif(Cache["username1"] == null){//登录Cache["username1"] = ...;}else{//已经登录了} 就是说,用application保存一个hash table对象,是这个意思不? logout的时候 清除掉就好了Cache["username1"] = null; 要防止同一用户同时登陆,首页应该记录在线用户的信息(这里与用户名为例),然后判断正在登陆的用户里面是否已存在。在这里使用一个cache存放已经登陆的用户名,但是还有一个问题就是要知道用户是什么时候离开系统的呢?这就要定期清除cache中的内容了,也就是设置一个cache的时间。这个时间可以跟用户的session值联系起来,刚好当用户session值失效的时候该用户在cache里面的信息也会被清空.这样就达到了防止同时登陆的效果,具体代码如下: 放在登陆成功的地方:string key = TextBox1.Text; //用户名文本框设为cache关键字 string uer = Convert.ToString(Cache[key]); //读取cache中用户相应的值//判断cache中是否有用户的信息,如果没有相关的值,说明用户未登陆if (uer == null || uer == String.Empty){ //定义cache过期时间 TimeSpan SessTimeout = new TimeSpan(0, 0, System.Web.HttpContext.Current.Session.Timeout, 0, 0); //第一次登陆的时候插入一个用户相关的cache值, HttpContext.Current.Cache.Insert(key, key, null, DateTime.MaxValue, SessTimeout, System.Web.Caching.CacheItemPriority.NotRemovable, null); Session["ADMINID"] = TextBox1.Text; Response.Redirect("main.aspx");}else{ //重复登陆 Response.Write("<script>alert('您的账号已经登陆!');window.location='login.aspx';</script>");} 就是说,用application保存一个hash table对象,是这个意思不?========>可以. 不用hash table也可以 cache application对象就相当于一个hash table 用cacheprivate void Button1_Click(object sender, System.EventArgs e) { string strUser=string.Empty; string strCacheKey = this.TextBox1.Text; strUser = Convert.ToString(Cache[strCacheKey]); if(strUser == string.Empty) { TimeSpan SessTimeOut = new TimeSpan(0,0,System.Web.HttpContext.Current.Session.Timeout,0,0); Cache.Insert(strCacheKey,strCacheKey,null,DateTime.MaxValue,SessTimeOut,CacheItemPriority.NotRemovable,null); Session["User"] = strCacheKey; this.Label1.Text = Session["User"].ToString(); } else { this.Label1.Text = "这个用户已经登录!"; } DropDownList绑定数据源出错 后台怎么得到本页所在的iframe名字 准备做一个自定义分页控件,请大家提需求 asp.net后台管理(散分) 如何让javascript 脚本写的弹出式窗口,有返回值 多个web项目如何合并? 为什么在VS2003中application的值在停止程序运行后,再次运行,其application中的值和上次的值一样 图片数据解析 我的WEB项目不能调试了,这是怎么回事??? 请问各位,datagrid中怎么控制行的绑定?谢谢!!! 帮忙看下为什么这样都不能防止IE缓存 大家好,我要做一个视频教学网,由我来主讲,可是不知道注册什么域名好,高人帮我想想
用hash table保存
if(Cache["username1"] == null)
{
//登录
Cache["username1"] = ...;
}
else
{
//已经登录了
}
Cache["username1"] = null;
string uer = Convert.ToString(Cache[key]); //读取cache中用户相应的值
//判断cache中是否有用户的信息,如果没有相关的值,说明用户未登陆
if (uer == null || uer == String.Empty)
{
//定义cache过期时间 TimeSpan SessTimeout = new TimeSpan(0, 0, System.Web.HttpContext.Current.Session.Timeout, 0, 0); //第一次登陆的时候插入一个用户相关的cache值,
HttpContext.Current.Cache.Insert(key, key, null, DateTime.MaxValue, SessTimeout, System.Web.Caching.CacheItemPriority.NotRemovable, null);
Session["ADMINID"] = TextBox1.Text;
Response.Redirect("main.aspx");
}
else
{
//重复登陆
Response.Write("<script>alert('您的账号已经登陆!');window.location='login.aspx';</script>");
}
========>
可以.
{
string strUser=string.Empty;
string strCacheKey = this.TextBox1.Text;
strUser = Convert.ToString(Cache[strCacheKey]);
if(strUser == string.Empty)
{
TimeSpan SessTimeOut = new TimeSpan(0,0,System.Web.HttpContext.Current.Session.Timeout,0,0);
Cache.Insert(strCacheKey,strCacheKey,null,DateTime.MaxValue,SessTimeOut,CacheItemPriority.NotRemovable,null);
Session["User"] = strCacheKey;
this.Label1.Text = Session["User"].ToString();
}
else
{
this.Label1.Text = "这个用户已经登录!";
}