惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
D
Docker
Blog — PlanetScale
Blog — PlanetScale
罗磊的独立博客
美团技术团队
V
V2EX
Last Week in AI
Last Week in AI
D
DataBreaches.Net
T
The Blog of Author Tim Ferriss
宝玉的分享
宝玉的分享
Microsoft Security Blog
Microsoft Security Blog
Microsoft Azure Blog
Microsoft Azure Blog
人人都是产品经理
人人都是产品经理
M
MIT News - Artificial intelligence
P
Proofpoint News Feed
B
Blog RSS Feed
博客园_首页
B
Blog
博客园 - 叶小钗
I
InfoQ
WordPress大学
WordPress大学
L
LangChain Blog
Apple Machine Learning Research
Apple Machine Learning Research
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
A
About on SuperTechFans
The GitHub Blog
The GitHub Blog
The Register - Security
The Register - Security
MyScale Blog
MyScale Blog
云风的 BLOG
云风的 BLOG
博客园 - 司徒正美
Latest news
Latest news
W
WeLiveSecurity
T
The Exploit Database - CXSecurity.com
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
aimingoo的专栏
aimingoo的专栏
小众软件
小众软件
Cyberwarzone
Cyberwarzone
Scott Helme
Scott Helme
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CERT Recently Published Vulnerability Notes
C
CXSECURITY Database RSS Feed - CXSecurity.com
Recent Commits to openclaw:main
Recent Commits to openclaw:main
N
News and Events Feed by Topic
S
Secure Thoughts
The Hacker News
The Hacker News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News

博客园 - sun@live

两段代码 <收藏>提高Web性能的14条法则(详细版) MOSS与业务系统的集成 之 自定义Membership实现Forms方式验证 手机归属地数据—采集 .Net数据源自定义参数 JavaScript和CSS速查手册 序列化一个字符串到CDATA元素(.NET 1.1) Sandcastle工具SandcastleBuilder 清除字符串数组中,重复元素 - sun@live - 博客园 Windows Live Writer 写的一个双向选择器(JS) 论坛中,用户权限解决方法 (原创)一个改自java的代码统计工具 Web2.0用户注册,激活,密码找回模块 [学习日志]EyasBlog控件部分已基本完成-2005-12-03 学习日志(blog日历控件)-2005年11月12日 学习日志(Blog架构)-2005年11月09日 学习日志-2005年11月09日 学习计划-2005年11月07日
MOSS与业务系统的集成 之 单点登录
sun@live · 2008-08-05 · via 博客园 - sun@live

2008-08-05 16:35  sun@live  阅读(572)  评论()    收藏  举报

前面MOSS与业务系统的集成 自定义Membership实现Forms方式验证文章中,我们实现了两系统的用户集成,下面要解决的是两系统间的单点登录问题。

部署在两台不同的服务器上的系统,要实现单点登录,最好的办法就是使用Cookie共享来实现了。只要将两系统使用同一根域名,并且用户保存用户登录票据的Cookie名称,以及Cookie加解密密钥一致即可。

  1. 业务系统的写cookie方式

     1 protected static void WriteCookie(string userName, bool isPersistent)
     2 {
     3             FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
     4                 1,
     5                 userName,
     6                 DateTime.Now,
     7                 DateTime.Now.AddMinutes(80),
     8                 isPersistent,
     9                 userName,
    10                 FormsAuthentication.FormsCookiePath);
    11             // Encrypt the ticket.
    12             string encTicket = FormsAuthentication.Encrypt(ticket);
    13             HttpCookie myCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
    14              
    15            //如果用户使用域名访问ADC,则在cookie上增加域名信息
    16               if (IsValidDomain(HttpContext.Current.Request.Url.Host))
    17             {
    18                 myCookie.Domain = FormsAuthentication.CookieDomain;
    19             }
    20 
    21             if (isPersistent)
    22             {
    23                 myCookie.Expires = ticket.Expiration;
    24             }
    25             // Create the cookie.
    26             HttpContext.Current.Response.Cookies.Add(myCookie);
    27 }
    28 
    29 protected static bool IsValidDomain(string strIn)
    30 {
    31             string strPattern = @"^\w+([-.]\w+)*\.\w+([-.]\w+)*$";
    32             return System.Text.RegularExpressions.Regex.IsMatch(strIn, strPattern);
    33 }
    34 

         
  2. 业务系统的web.config修改

    <!--Cookie名称与根域名需一致-->
    <authentication mode="Forms">
          
    <forms name="CookieName"  domain=".domain.com" path="/" ></forms>
    </authentication>

  3. Moss站点的web.config修改 

    <!--将MOSS站点web.config中machineKey配置复制到业务系统中,两系统保持一致即可 -->
    <machineKey validationKey="C57043728999BCF9537BA55F5978F50722C91B26A0F9D34F"
       decryptionKey
    ="C57043728999BCF9537BA55F5978F50722C91B26A0F9D34F"
       validation
    ="SHA1" /><!--Cookie名称与根域名也需一致-->
    <authentication mode="Forms">
          
    <forms name="CookieName"  domain=".domain.com" path="/" ></forms>
    </authentication>