IIS实现单点登录

该博客详细介绍了如何在IIS上设置单点登录(SSO)系统,包括创建3个MVC Web应用程序(登录中心RedisSso及两个子网站RedisWeb1和RedisWeb2),在IIS中添加网站,编辑hosts文件,引入ServiceStack.Redis库,定义用户类、操作结果类和上下文类,以及在各个项目中配置Web.config文件和实现登录逻辑。
摘要由CSDN通过智能技术生成

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">
    <
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值