仓酷云
标题:
ASP网页编程之让Session工具在分歧域名下完成共享
[打印本页]
作者:
再现理想
时间:
2015-1-16 22:32
标题:
ASP网页编程之让Session工具在分歧域名下完成共享
问题是他们究竟是喜欢他们是使用软件时,速度快还是速度慢好.(当然在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写得更有效率和更方便重用
作者:
变相怪杰
时间:
2015-1-19 16:22
以上是语言本身的弱点,在功能方面ASP同样存在问题,第一是功能太弱,一些底层操作只能通过组件来完成,在这点上是远远比不上PHP/JSP,其次就是缺乏完善的纠错/调试功能,这点上ASP/PHP/JSP差不多。
作者:
因胸联盟
时间:
2015-1-25 21:06
ASP.Net和ASP的最大区别在于编程思维的转换,而不仅仅在于功能的增强。ASP使用VBS/JS这样的脚本语言混合html来编程,而那些脚本语言属于弱类型、面向结构的编程语言,而非面向对象,这就明显产生以下几个问题:
作者:
admin
时间:
2015-2-4 02:49
我认为比较好的方法是找一些比较经典的例子,每个例子比较集中一种编程思想而设计的。
作者:
柔情似水
时间:
2015-2-9 12:00
没有坚实的理论做基础,那么我们连踏入社会第一步的资本都没有,特别对于计算机专业的学生学好专业知识是置关重要的。在这里我侧重讲一下如何学习ASP,从平时的学习过程中。
作者:
精灵巫婆
时间:
2015-2-27 06:07
不是很难但是英文要有一点基础网上的教程很少有系统的详细的去买书吧,另不用专门学习vb关于vbscript脚本在asp教材都有介绍
作者:
愤怒的大鸟
时间:
2015-3-8 22:44
不能只是将它停留在纸上谈兵的程度上。
作者:
海妖
时间:
2015-3-16 16:29
接下来就不能纸上谈兵了,最好的方法其实是实践。实践,只能算是让你掌握语言特性用的。而提倡做实际的Project也不是太好,因为你还没有熟练的能力去综合各种技术,这样只能使你自己越来越迷糊。
作者:
分手快乐
时间:
2015-3-22 23:43
尽管MS自己讲C#内核中更多的象VC,但实际上我还是认为它和Java更象一些吧。首先它是面向对象的编程语言,而不是一种脚本,所以它具有面向对象编程语言的一切特性,比如封装性、继承性、多态性等等,这就解决了刚才谈到的ASP的那些弱点。
欢迎光临 仓酷云 (http://ckuyun.com/)
Powered by Discuz! X3.2