日期:2014-05-17 浏览次数:20667 次
if (Session["LoginUser"] != null)
{
Uname = Session["LoginUser"].ToString();
}
else
{
objJs.JsAlert("对不起,您没有登录");
Response.Redirect("~/login.aspx");
}
if (!IsPostBack)
{
this.Label1.Text = Uname + "! 您登录成功了!";
}
string uname = (string)Session["LoginUser"];
if(uname == null)
{
//没有登陆,或超时
//退出或其他动作
}
else
{
//验证成功
//更多动作
}
------解决方案--------------------
protected void i_login_Click(object sender, ImageClickEventArgs e)
{
try
{
try
{
判读用户是否存在
判断用户是否启用
判断密码
SetSession(Usersession);
Application[Usersession.UserID.ToString()] = 登陆时间;//用于判读登陆超时
Response.Redirect("index.aspx");
}
catch (Exception ex)
{
}
}
catch (Exception ex)
{
}
}
------解决方案--------------------
只要是安全性要求不很高的网站 那样子已经足够了
否则的话 要对用户信息进行加密解密
------解决方案--------------------
需要判断 重复登陆 的 情况
asp.net 实现 单点登录实现思路
利用Cache的功能,我们把用户的登录信息保存在Cache中,并设置过期时间为Session失效的时间,因此,一旦Session失效,我们的Cache也过期;而Cache对所有的用户都可以访问,因此,用它保存用户信息比数据库来得方便。
程序代码
string sKey = username.Text.ToString().Trim(); // 得到Cache中的给定Key的值
string sUser = Convert.ToString(Cache[sKey]); // 检查是否存在
if (sUser == null || sUser == String.Empty)
{
TimeSpan SessTimeOut = new TimeSpan(0, 0, System.Web.HttpContext.Current.Session.Timeout, 0, 0);//取得Session的过期时间
HttpContext.Current.Cache.Insert(sKey, sKey, null, DateTime.MaxValue, SessTimeOut, System.Web.Caching.CacheItemPriority.NotRemovable, null);//将值放入cache己方便单点登录
//成功登录
}
else if (Cache[sKey].ToString() == sKey)//如果这个账号已经登录
{
ClientScript.RegisterStartupScript(GetType(), "提示", "<script>alert('对不起,当前用户已经登录');</script>");
return;