仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 349|回复: 8
打印 上一主题 下一主题

[学习教程] ASP网页编程之让Session工具在分歧域名下完成共享

[复制链接]
再现理想 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-16 22:32:37 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

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

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-9-28 14:13

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表