网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > ASP技巧
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.用ASP实现网页BBS.
.访问IIS虚拟目录需要权限的解决办.
.ASP的错误处理集锦.
.处理二进制数据.
.在网页中实现OICQ里的头像选择的.
.WINDOWS 2000搭載ASP3.0和IIS5.0.
.怎样在ASP里面创建统计图表.
.ASP服务器组件编程心得.
.从ASP调用SQL中的图像.
.IIS的一个莫名错误Server Applic.
.Varchar与char的区别.
.一个高效的数据分页的存储过程.
.如何将代码生成的文件设为只读.
.页边距的设定技巧(HTML).
.用ASP发 WAP MAIL(=).
.使用split分割多字符的字符串的方.
.使用ADO批量更新记录(源代码).
.ASP如何使用MYSQL数据库.
.表单填写时用回车代替TAB的实现方.
.用ASP打开远端MDB文件.

让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



上一篇:一个普通的数据库例子源源程序 人气:13164
下一篇:无组件图片与文本同步存入数据库的最简单的办法 人气:13430
浏览全部Session的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐