|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
问题是他们究竟是喜欢他们是使用软件时,速度快还是速度慢好.(当然在3秒以内).无论是他们输入资料时,查找资料时,分析资料时.Thereisageneralbeliefamongdevelopersthatsessionstatemaintenanceisalwaysagainstone
domain/site.Andthereforeonecannotmaintainsessionstateacrossdifferentdomains.Usuallythereis
nosuchrequirementtomaintainsessionstateacrossdifferentdomains.Butoflateduetoincreaseinthe
scopeofwebbasedapplicationsdevelopersfeeltheneedtosharethesessionstatewithotherdomains.
Theotherdomainmaybeasisterconcernofthesamecompany,ormaybetheB2Bpartner.Sothequestion
ariseshowonecansharethesessionvariablesacrossotherdomainseasilyandsafely.
--------------------------------------------------------------------------------
HowtoshareSessionvariablesacrossDomains
Introduction
Thereisageneralbeliefamongdevelopersthatsessionstatemaintenanceisalwaysagainstone
domain/site.Andthereforeonecannotmaintainsessionstateacrossdifferentdomains.Usuallythereis
nosuchrequirementtomaintainsessionstateacrossdifferentdomains.Butoflateduetoincreaseinthe
scopeofwebbasedapplicationsdevelopersfeeltheneedtosharethesessionstatewithotherdomains.
Theotherdomainmaybeasisterconcernofthesamecompany,ormaybetheB2Bpartner.Sothequestion
ariseshowonecansharethesessionvariablesacrossotherdomainseasilyandsafely.
SharingSessionvariablesusingaSMS
ConfigureaSMS
SharingSessionvariablesacrossdomainsisveryeasyusingaSMS.aSMSStandardandAdvancedboth
supportsharingsessionvariables.Letsassumetwodifferentdomainsmydomain1.comandmydomain2.com.And
therequirementistosharethesessionvariablesbetweenmydomain1.comandmydomain2.com.Forsimplicity
sakeletsassumeonewebservereachformydomain1.comandmydomain2.com.(It’salsopossiblesoshare
sessionvariablesbetweendifferentdomainshostedonsamewebserver).Sowww.mydomain1.compointsto
webserverofdomain1andwww.mydomain2.compointswebserverofmydomain2.com.
InstallaSMSonbothwebservers.BothaSMSshouldshareacommonLDAPservertosharesessionvariables.
LetsassumethatcommonLDAPserverbeldap.mydomain.com.Onthewebserverofmydomain1.com,opentheaSMS
AdminConsole.
Forthe,
LDAPPathenterLDAP://ldap.mydomain.com:1002/o=mydomain/ou=Members
LDAPAdminentercn=Administrator,ou=Members,o=mydomain
EntertheAdminPassword.SetyourSessionTimeoutduration.Ifyouwanttosupportcookiesthenset
SupportCookiestoTrue.
Click‘TestLDAPSource’button.Ifitreturns‘Successful’ThenaSMShasbeenconfiguredsuccessfully
onthewebserverofmydomain1.com.
Dothesameonthewebserverofmydomain2.com.TakecaretoenterthesameLDAPpath
(LDAP://ldap.mydomain.com:1002/o=mydomain/ou=Members)forthewebserverofmydomain2.com.Thiswaywe
ensurethataSMSofbothwebserverspointtothesameLDAPServer.TestLDAPconnectionbyclicking‘test
LDAPsource’button.IfitreturnssuccessfulthenaSMShasbeenconfiguredproperlyonwebserverof
mydomain2.comalsoandtheybothpointtothesameLDAPserver.
StartSessiononWebserverofmydomain1.com
Onecanusethefunctions.asp(linktofunction.txt)giveninthesamplefilesandincludethisfilein
allasppages.Iffunctions.asphasbeenusedthenSessioncanbestartedbyjustcallingSessionStart
functiononthedefault.aspofmydomain1.comwebserver.
Iffunction.aspisnotused,thenfollowingcodecanbeusedtostartthesessionindefault.asppage
<%
SetobjSession=Server.CreateObject("Session.Management")
objSession.SessionStart()
SetobjSession=nothing
%>
Toassignsessionvariablesinmydomain1.com
<%
SetobjSession=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
SetobjSession=nothing
%>
ToretrieveSessionvariables
<%
DimstrFirstName,strLastName,strEmailAddress
DimstrPassword,intStatus
SetobjSession=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")
SetobjSession=nothing
%>
SharingSessionVariables
Tosharethesessionvariablesbetweendomains,oneneedtopasstheSessionGUIDvaluetotheother
domain.aSMSmaintainssessionbyusingthisSessionGUID.Thiscanbedonebypassingthe‘SessionGUID’
cookievaluetootherdomainbyeitherquerystringorbyhiddenformfield.
<ahref=http://www.mydomain2.com/default.asp?SessionGUID=<%=Request.Cookies(“SessionGUID”)%>>
MyDomain2.com</a>
AddfewlinesjustafterSessionStartcodeindefault.aspofmydomain2.comdomain.
<%
SetobjSession=Server.CreateObject("Session.Management")
IfRequest.QueryString("SessionGuid")""Then
Response.Cookies("SessionGuid")=Request.QueryString("SessionGuid")
Else
objSession.SessionStart()
EndIf
SetobjSession=nothing
%>
Toretrievemydomain1.com’ssessionvariables
<%
DimstrFirstName,strLastName,strEmailAddress
DimstrPassword,intStatus
SetobjSession=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
%>
ThiswaywecansharesessionvariablesbetweentwodifferentdomainsusingaSMS.
Scenarios,wheresharingSessionVariablesAcrossDomainsmayberequired
Sharingsessionvariablesisrequiredinsomanytypesofwebscenarios.Someofthemare-
1.CommonLoginbetweentwodifferentdomains-Ifyoudon’twanttheuserswhohaveloggedin
mydomain1.comtoonceagainbevalidatedinmydomain2.com.
2.SharingSessionvariableswithyourB2Bpartner.
3.Developingyourown‘MicrosoftPassport’likewebsite.
Conclusion
HerewehaveseenhowbyusingaSMSonecaneasilysharesessionvariablesacrosstwodifferent
domains.Thismethodhasbeenactuallyimplementedonlivewebsites.Menswear.com
(http://www.menswear.com)andWomenswear.net(http://www.womenswear.net)useaSMStosharesessionstate
acrosstwooftheirdomains.Whenusersgofrommenswear.comtowomenswear.com,theyneednotre-login.
Usersneedtologinonlyateithermenswear.comoratwomenwear.com.Theauthenticationdetailsareshared
betweentwodomains.
Downloadsamplecodeforthispage.
http://files.driveway.com/download/vapp03-653b18dcaf1f3ccb/28271119/Sharing+Session+Variables+Samples.zip
ASP.NET和ASP的比较,技术上比较已经没什么可说的了.新一代在大部分程度来说当然是比旧一代好了.关键看你对所做软件的理解了.因人而定.会写的话也可能比ASP.NET写得更有效率和更方便重用 |
|