设为首页 收藏本站
| 数控仿真 | 编程软件 | 技术文章 | 数控大赛 | 斐克科技 | 公路造价 | 文档备份 |
| 幸运之门彩票网 | 彩票论坛 | 彩票新闻 | 免费招聘 | 百科问吧 | 百姓族谱 | 小游戏网 |
奥运会形象
C#(CSharp) | VC/C++ | C++Builder | ASP(ASP.NET) | SQL Server | OpenGL | CMM | Web | NC | GIS | OS | 免费小游戏 | 彩票论坛
Google
联高软件 > 技术文章 > VB(ASP)/VB.NET > 让SESSION对象在不同域名下实现共享
VB(ASP)/VB.NET | VC/VC++/VC.NET | C#(CSharp) | C++Builder | Java/JSP | EJB/J2EE |
让Session对象在不同域名下实现共享

发表:联高软件www.legalsoft.com.cn,本文被阅读:1

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
 联高软件 > 技术文章 > VB(ASP)/VB.NET
·一种理论上最快的Web数据库分页方法 (1503)
·ASP编码优化技巧8则 (1396)
·超酷三维汉字特效 (1587)
·用HttpWebRequest和正则表达式提取网页中的链接 (2440)
·五种常见的ASP.NET安全缺陷 (1372)
·ASP和ASP.NET的MD5加密中文结果不同原因 (228)
·使用ASP.NET 2.0 输出缓存替换的功能实现“甜圈缓存(Donut Caching)” (196)
·在ASP.NET中自动给URL地址加上超链接 (255)
·asp重定向 (287)
·不用 EOF 以加快记录循环(vb) (317)
·asp和asp.net共享session解决办法 (243)
·在ASP与ASP.NET之间共享对话状态 (993)
·完整的网站间共享数据的WebService (749)
·如何用非对称密码算法制作共享软件的注册码 (3667)
·在C++Builder中创建共享内存段 (1502)
 最新文章
·如何使用SQLSERVER2000中的XML功能
·超强C#图片上传,加水印,自动生成缩略图
·C#中用SYSTEM.XML读写XML说明与代码
·C#取真实IP地址及分析
·C#+DIRECT3D9.0开发实例之月亮绕着地球转
·ASP程序员学习C#之超级攻略
·通过C#实现集合类纵览.NETCOLLECTIONS及
·C#开发WAP程序实例
·C#3.0中对象初始化器和集合初始化器
·C#3.0新特性速览
·ASP和ASP.NET的MD5加密中文结果不同原因
·CSS截取固定长度字符串
·简单实用的C#分词源代码(含词库素材下载
·C#高效分页代码(不用存储过程)
·SERVER.TRANSFER是在两个页面之间进行传
·一个克隆对象的C#基类
·C#语言FTP客户端代码
·递归枚举排列、组合的C#源码
·在C#.NET中跟踪代码的运行过程
·ASP.NET2.0中实现跨页面提交
·C#通用的数据操作类
·常用的C#数据检查类
·C#中的域(FIELD)和属性(PROPERTY)
·C#编码规范和编程好习惯
·C#编码好习惯
·用C#实现C/S模式下软件自动在线升级
·C#参考之访问关键字:BASE、THIS
·C#实现遗传算法模拟花朵的进化
·用C#的类实现数据结构的堆栈算法
·在C#中应用哈希表(HASHTABLE)
·用C#生成中文汉字验证码的基本原理
·C#.NET支付宝接口
·在C#中利用SHARPZIPLIB进行文件的压缩和
·程序员必须知道的SQLSERVER数据库优化技
·360度全方位比较C#和VB
·C#设计模式之建造者(BUILDER)模式示例源
·C#抽象工厂模式的几种实现方法及比较
·用设计模式固化C#程序
·数据结构与算法(C#实现)系列---二叉树
·在C#中建立复杂的、灵活的SQL查询/命令
·解读C#中的正则表达式
·对C#开发的两个基本原则的深入讨论
·正则表达式使用高级技巧之组的概念
·模板和泛型如何配合使用
·C#中提供的VB不支持的新特性
·关于C#在LUCENE.NET下的中文切词
·无废话C#设计模式之十:FLYWEIGHT
·无废话C#设计模式之十一:COMPOSITE
·无废话C#设计模式之十二:BRIDGE
·无废话C#设计模式之十三:DECORATOR
 热门文章
·程序员必须知道的SQLSERVER数据库优化技
·OpenGL 入门教程(一)
·OpenGL基础篇
·使用回调函数(VC & Delphi)
·OpenGL 入门教程(二)
·数控加工技术试题库
·C++Builder的一些技巧
·矩阵相乘的快速算法
·如何实现进程间数据通讯技术
·数控考题(二)
·矩阵求逆的快速算法
·数控试题(一)
·第一个三角形:NeHe的OpenGL第二课
·Universal Geospatial Data Exchange
·TServerSocket和TClientSocket的使用
·地理信息系统中的常规网络分析功能及相关
·选择与反馈 (OpenGL)
·数控车床加工编程典型实例分析
·函数调用的几个概念:_stdcall,_cdecl..
·OpenGL 入门教程(三)
·Dijkstra 最短路径算法的一种高效率实现
·OpenGL 入门教程(六)
·OpenGL 入门教程(四)
·应用程序的网上升级-VB
·自己绘制True type font字体
·OpenGL 入门教程(五)
·数控车床基本坐标关系及几种对刀方法比较
·数控机床标准M代码
·OpenGL 入门教程(七)
·关于VC多文档应用中OpenGL的使用
免费小游戏
宠物连连看

真人美女换装

美女脱衣服

美女胴体猜猜看

调戏床上美女

黄金矿工
七乐彩投注
| 幸运之门 | 免费招聘 | 小游戏网 | 百科问吧 | 国际机票 | 我的信息 | 技术文章 | 文档备份 | 公路造价软件 | 联系我们 | 广告代理 | 媒体合作 | 免责条款 |
北京联高软件开发有限公司 1999-2008© 京ICP备05034864号 工商
地址:北京市海淀区中关村北二条13号中科科仪1号楼5层 地图
电话:010-82386887 010-62343002