同域名下多WEB应用的单点登录

已经配了2个应用,都花了不少时间,除第一次是上手的过程可以理解,第二次的问题主要是记性太差,才半年的时间就有很多要点都漏掉了,因此开博记录下自己的思路,以免事不过三。

 

--------------------------------------web.config设置

 

<!-- 单点认证需要 -->
    <authentication mode="Forms">
       <forms loginUrl="Login.aspx" name=".abc"  domain=".***.com.cn" protection="All" path="/" timeout="1440" slidingExpiration="false"/> 
    </authentication>
    <authorization>
      <allow users="*" />
    </authorization>

    <machineKey validationKey="3505A10867B21A9BD7EBE80CBD00E005D1367D5C389C167C"
         decryptionKey="1DBA63BA352BBBDCCAFBA6A60D7BC1D1258F77A2BB0F4E82"
         validation="SHA1" decryption="3DES"/>

 

name=".abc"  domain=".***.com.cn" 配置要点,确保.abc作为Cookie出现在domain中,可以通过火狐的cookie管理器看到。

 

machineKey 咨询GOOGLE

--------------------------------------后台代码,有时间验证是否可在JS中实现如下键值的存储

            public static string ID
            {
                get
                {
                    string Result = string.Empty;
                    if (HttpContext.Current.Request.Cookies["ID"] != null)
                    {
                        Result = HttpContext.Current.Request.Cookies["ID"].Value;
                    }

                    return Result;
                }
                set
                {
                    HttpContext.Current.Response.Cookies["ID"].Value = value;
                    HttpContext.Current.Response.Cookies["ID"].Domain = ".***.com.cn";
                }
            }

            public static void ClearCookie()
            {
                //清空所有Cookie
                int count = HttpContext.Current.Request.Cookies.Count;

                for (int i = 0; i < count; i++)
                {
                    HttpCookie cookie = HttpContext.Current.Request.Cookies[i];
                    cookie.Domain = Domain;
                    cookie.Expires = DateTime.Now.AddHours(-24); //关键是这一句

                    HttpContext.Current.Response.Cookies.Add(cookie);

                }
            }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值