How to share session variables into SS domains (share sessions between different domains)

Source: Internet
Author: User
Tags ldap test ldap connection

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 limit SS different domains. Usually there is
No such requirement to maintain session State failed SS 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 within SS other domains easily and safely.
Sharing Session variables using ASMs
Configure ASMs
Sharing Session variables kernel SS 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 shocould 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,
LDAP path enter LDAP: // 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 'sessiongu'
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 ydomain2.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 writable SS 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 into SS 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
Using SS 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://www.planet-source-code.com/vb/scripts/ShowCode.asp? Lngwid = 4 & txtcodeid = 6245

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.