动态网站制作指南



当前位置 > 网站建设学院 > 网络编程 > ASP技巧 Rss
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket

让Session对象在不同域名下实现共享


发表日期:2000-10-13


There is a general belief among developers that session state maintenance is always against one
domain / site. And therefore one can not maintain session state across different domains. Usually there is
no such requirement to maintain session state across different domains. But of late due to increase in the
scope of web based applications developers feel the need to share the session state with other domains.
The other domain may be a sister concern of the same company, or may be the B2B partner. So the question
arises how one can share the session variables across other domains easily and safely.

--------------------------------------------------------------------------------


  
How to share Session variables across Domains


Introduction  
      There is a general belief among developers that session state maintenance is always against one
domain / site. And therefore one can not maintain session state across different domains. Usually there is
no such requirement to maintain session state across different domains. But of late due to increase in the
scope of web based applications developers feel the need to share the session state with other domains.
The other domain may be a sister concern of the same company, or may be the B2B partner. So the question
arises how one can share the session variables across other domains easily and safely.

  

Sharing Session variables using aSMS  
     
      Configure aSMS


      Sharing Session variables across domains is very easy using aSMS. aSMS Standard and Advanced both
support sharing session variables. Lets assume two different domains mydomain1.com and mydomain2.com. And
the requirement is to share the session variables between mydomain1.com and mydomain2.com. For simplicity
sake lets assume one webserver each for mydomain1.com and mydomain2.com. (It’s also possible so share
session variables between different domains hosted on same webserver). So www.mydomain1.com points to
webserver of domain1 and www.mydomain2.com points webserver of mydomain2.com.

Install aSMS on both webservers. Both aSMS should share a common LDAP server to share session variables.
Lets assume that common LDAP server be ldap.mydomain.com. On the webserver of mydomain1.com, open the aSMS
Admin Console.

For the,

LDAP Path enterLDAP://ldap.mydomain.com:1002/o=mydomain/ou=Members
LDAPAdminentercn=Administrator,ou=Members,o=mydomain

Enter the Admin PassWord. Set your Session Time out duration. If you want to support cookies then set
Support Cookies to True.




Click ‘Test LDAP Source’ button. If it returns ‘Successful’ Then aSMS has been configured successfully
on the webserver of mydomain1.com.




Do the same on the webserver of mydomain2.com. Take care to enter the same LDAP path
(LDAP://ldap.mydomain.com:1002/o= mydomain/ou=Members)for the webserver of mydomain2.com. This way we
ensure that aSMS of both webservers point to the same LDAP Server. Test LDAP connection by clicking ‘test
LDAP source’ button. If it returns successful then aSMS has been configured PRoperly on webserver of
mydomain2.com also and they both point to the same LDAP server.

  
     
Start Session on Webserver of mydomain1.com


  One can use the functions.asp (link to function.txt) given in the sample files and include this file in
all asp pages. If functions.asp has been used then Session can be started by just calling SessionStart
function on the default.asp of mydomain1.com webserver.

If function.asp is not used, then following code can be used to start the session in default.asp page

< %

Set objSession = Server.CreateObject("Session.Management")

objSession.SessionStart()

Set objSession = nothing

% >

To assign session variables in mydomain1.com

< %

Set objSession = Server.CreateObject("Session.Management")

objSession.CheckSession()

objSession.SetSession "givenname", John

objSession.SetSession "sn", Anderson

objSession.SetSession "mail", John@Anderson.com

objSession.SetSession "userPassword", password

objSession.SetSession "accountStatus ", 1

Set objSession = nothing

% >

To retrieve Session variables

< %

Dim strFirstName, strLastName, strEmailAddress

Dim strPassword, intStatus

Set objSession = Server.CreateObject("Session.Management")

objSession.CheckSession()

strFirstName = objSession.GetSession ("givenname")

strLastName = objSession.GetSession ("sn")

strEmaiAddress = objSession.GetSession ("mail")

strPassword = objSession.GetSession ("userPassword")

intStatus = objSession.GetSession ("accountStatus ")

Set objSession = nothing

% >

  
     
Sharing Session Variables   


      To share the session variables between domains, one need to pass the SessionGUID value to the other
domain. aSMS maintains session by using this SessionGUID. This can be done by passing the ‘SessionGUID’
cookie value to other domain by either query string or by hidden form field.

<ahref=http://www.mydomain2.com/default.asp?SessionGUID= <%= Request.Cookies (“SessionGUID”)% > >
MyDomain2.com< /a>

Add few lines just after SessionStart code in default.asp of mydomain2.com domain.

< %

Set objSession = Server.CreateObject("Session.Management")

If Request.QueryString ("SessionGuid") <> "" Then

Response.Cookies ("SessionGuid") = Request.QueryString ("SessionGuid")

Else

objSession.SessionStart()

End If

Set objSession = nothing

% >

To retrieve mydomain1.com’s session variables

< %

Dim strFirstName, strLastName, strEmailAddress

Dim strPassword, intStatus

Set objSession = Server.CreateObject("Session.Management")

objSession.CheckSession()

strFirstName = objSession.GetSession ("givenname")

strLastName = objSession.GetSession ("sn")

strEmaiAddress = objSession.GetSession ("mail")

strPassword = objSession.GetSession ("userPassword")

intStatus = objSession.GetSession ("accountStatus ")  

objSession = nothing

% >  

This way we can share session variables between two different domains using aSMS.

  
     
Scenarios, where sharing Session Variables Across Domains may be required


Sharing session variables is required in so many types of web scenarios. Some of them are-

1. Common Login between two different domains - If you don’t want the users who have logged in
mydomain1.com to once again be validated in mydomain2.com.

2. Sharing Session variables with your B2B partner.

3. Developing your own ‘Microsoft Passport’ like web site.


  

Conclusion    
  
       Here we have seen how by using aSMS one can easily share session variables across two different
domains. This method has been actually implemented on live web sites. Menswear.com
(http://www.menswear.com) and Womenswear.net (http://www.womenswear.net ) use aSMS to share session state
across two of their domains. When users go from menswear.com to womenswear.com, they need not re-login.
Users need to login only at either menswear.com or at womenwear.com. The authentication details are shared
between two domains.

Download sample code for this page.
http://files.driveway.com/download/vapp03-653b18dcaf1f3ccb/28271119/Sharing+Session+Variables+Samples.zip



关注此文的读者还看过:
·2012-5-22 16:42:04 ASP.NET MVC 框架
·2012-5-22 16:41:35 ASP中和星期有关的自定义函数
·2012-5-22 16:41:32 一个高效的数据分页的存储过程
·2012-5-22 16:41:30 不能ASP图像组件来生成图像的ASP计数器程序(二) 
·2012-5-22 16:41:02 Webservice调用方式
·2012-5-22 16:40:48 在asp中如何创建动态表--调用如下sp_execute
·2012-5-22 16:40:20 如何设置二级域名?
·2012-5-22 16:40:01 如何读出空格
·2012-5-22 16:39:22 ASP将两个数组合并为一个数组函数 array_merge()
站长推荐 PS笔刷下载 在线翻译 系统进程 广告代码
  发表评论
姓 名: 验证码:
内 容:
教程搜索服务
ASP源码推荐
·梦迟贴吧-单版面版内部测试版 v
·ASBLOG v2.5 Build 081227
·公安网络在线报警系统
·涂鸦部落可爱留言本(单用户版)
·同策论坛TCBBS 2006 精装版
·ExpoCMS展览行业网站系统 v1.8
·落叶飘flash整站 v2.0
·零距离QQ挂机大全 v1.0
·互动信息管理系统IIMS 2006 Bui
·赏金猎手论坛安全版
·易心多模版单用户博客程序 v1.1
·艺术图库新云无图版 Build 0808
项目外包信息
·寻会php的程序员外包网站
·派桑网络-网络营销专家
·汽车配件网站制作 50000元
·整站SEO优化
·课件门户网程序
·求长期合作网站设计制作高手
·公司网站重新改版 8000元
·asp企业网站小改动
·网站flash片头
·文化传播公司网站设计稿
·UI界面设计
·产品外观改版设计 15000元
·照明灯具网站设计 10000元
·求长期合作网站设计制作高手
·做B2C网站 20000元
发布信息 浏览信息
邮件订阅服务
输入你的邮件地址,你将不会错过任何关于<ASP技巧>的内容


网络编程文章分类
ASP教程
ASP实例
ASP技巧
ASP文摘
PHP教程
PHP技巧
PHP实例
PHP文摘
JSP教程
JSP技巧
JSP实例
JSP文摘
ASP.NET教程
ASP.NET技巧
ASP.NET实例
ASP.NET应用
xml教程
xsl教程
xml技巧
C#教程
C#应用
Delphi教程
Perl教程
Shell教程
Ajax教程
Visual Basic教程
Java教程
J2EE/J2ME教程
C/C++教程
移动解决方案
移动短信技术
移动行业动态
软件工程
WordPress
Android开发
站长工具:Google PR查询|Alexa排名查询|网站速度测试|CSS在线编辑器|OPEN参数生成器|弹出式窗口代码产生器|密码登录生成器|在线按钮生成器|Meta标签生成器|邮箱图标在线生成|多色彩特效字代码生成器|网页代码调试器|在线FTP登陆|Flash取色器|配色代码对照表|配色辞典|CSS生成器|CSS在线压缩|广告代码|框架网页代码生成器|js/vbs加密|md5加密|进制转换|UTF-8 转换工具|在线调色板|Html转换js|Html转换asp|Html转换php|Html转换perl
实用工具:汉字翻译拼音|拼音字典|在线翻译|天气预报|火星文|在线网速测试|符号对照表|个税计算|理财工具|黄金价格|购房银行按揭利率计算|汇率查询|经典小工具|汉字简繁转换|普通单位换算|公制单位换算|生辰老黄历|国内电话区号|国家代码与域名缩写|文字加密解密|元素周期表|健康查询|世界时间|全国各地车牌查询|全国车辆交通违章查询|万年历|二十四节气|汉字横竖排版|手机号码查询|计算器|ip搜索|酒店预订|机票预订
广告刊登 | 版权声明 | 联系我们 | 加入收藏 | RSS订阅
Copyright © 2000-2012 www.knowsky.com All rights reserved | 沪ICP备05001343号