当前位置: 移动技术网 > IT编程>开发语言>.net > asp.net 简单单点登录技术分析

asp.net 简单单点登录技术分析

2017年12月12日  | 移动技术网IT编程  | 我要评论
代码如下: 复制代码 代码如下: ///单点登录(single sign on) public void ssomethods(string username, strin
代码如下:
复制代码 代码如下:

///单点登录(single sign on)
public void ssomethods(string username, string password)
{
//判断登录情况 此处方法省略……
int result = checklogin(username, password);
if(result>0)
{
//唯一标识,可自行设定
string key = string.format("{0}_{1}",username, password);
//得到cache中的key值
string usercache = cache[key].tostring();
//判断是否为空
if(string.isnullorempty(usercache))
{
timespan sessiontimeout = new timespan(0,0,httpcontext.current.session.timeout,0,0);
httpcontext.current.cache.insert(key,key,null,datetime.maxvalue,sessiontimeout,cacheitempriority,notremovable,null);
session["user"] = key;
response.write("<font color=red>登录成功!</font>");
}
else
{
repsonse.write("<font color=red>抱歉,您已经在其他地方登录了!</font>");
return;
}
}
else
{
response.write("用户名不存在!");
}
}

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网