1.首先建立3个MVC Web网站 一个登录中心RedisSso 以及两个其他网站:RedisWeb1、RedisWeb2
2.在IIS管理器中添加三个网站
2.1找到C:\Windows\System32\drivers\etc\hosts文本中添加IIS所部署的网站
3.三个Web项目皆添加Nuget程序包-->ServiceStack.Redis
4.RedisSso、RedisWeb1、RedisWeb2皆添加一个UserInfo用户类、OperateResult操作结果类、UserContext上下文类
public class UserInfo
{
//用户名
public string UserName { get; set; }
//密码
public string PassWord { get; set; }
}
public class OperateResult //操作结果类
{
//状态
public string status { get; set; }
//信息
public string info { get; set; }
//是否成功
public bool Success { get; set; }
//跳转地址
public string Url { get; set; }
}
public class UserContext //管理下上文类
{
/// <summary>
/// 静态上下文类
/// </summary>
public static UserContext userContext = new UserContext();
//会话的key
private string SessionKey = "ADMININFO_KEY";
//会话状态
public HttpSessionState httpSessionState => HttpContext.Current.Session;
//管理信息
public UserInfo UserInfo
{
get
{
return httpSessionState[SessionKey] as UserInfo;
}
set
{
httpSessionState[SessionKey] = value;
}
}
}
5.RedisSso登录中心项目中Web.config文件配置AppSettings节点
<!--Redis服务器-->
<add key="RedisServer" value="127.0.0.1" />
<!--过期时间-->
<add key="TimeOut" value="30" />
<!--默认跳转站点-->
<add key="DefaultUrl" value="http://www.RedisWeb1.com" />
6.RedisWeb1、RedisWeb2项目中Web.config文件配置AppSettings节点
<!--Redis服务器-->
<add key="RedisServer" value="127.0.0.1" />
<!--过期时间-->
<add key="TimeOut" value="30" />
<!--SSO验证服务器-->
<add key="UserAuthUrl" value="http://www.RedisSso.com" />
7.RedisSso的Home文件添加Login页面
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>管理员登陆 - 统一权限管理平台</title>
<link rel="stylesheet" href="~/Scripts/static/common/layui/css/layui.css">
<