你可以共享两个.NET 2.0+应用程序之间的会话变量? [英] Can you share the session variables between two .net 2.0+ applications?
问题描述
有人告诉我这个工作,但...
I was told this works, but...
我想我只是没有得到这一点,似乎有一个隐藏的一步,我可能会丢失,任何人都可以纠正这种或指出我的错误?谢谢你。
I guess I'm just not getting this, it seems there's a hidden step I may be missing, can anyone correct this or point out my mistake? Thanks.
我有一个空白的解决方案:
- 里面是二.NET 2.0的Web应用程序
1)webapp1
2)webapp2的
I have a blank solution:
- inside is two .net 2.0 web applications
1) webapp1
2) webapp2
我希望他们能够共享相同的会话数据。
I want them to share the same session data.
我的页面设置:
应用1:
Session("value") = "this is the value"
应用2:
If Not (Session("value") Is Nothing) Then
value = Session("value").ToString()
End If
我的思维过程:
1)去服务,开启asp.net状态服务
2)在两个项目打开网页的configs:设置
1) go to services, turn on the asp.net state service
2) open the web configs in both projects: set the
< machineKey
validationKey="BFE2909A81903BB303D738555FEBC0C63EB39636F6FEFBF8005936CBF5FEB88CE327BDBD56AD70749F502FF9D5DECF575C13FA2D17CA8870ED21AD935635D4CC"
decryptionKey="2A86BF77049EBA3A2FA786325592D640D5ACD17AF8FFAC04" validation="SHA1" />
< sessionState mode="StateServer" stateConnectionString="tcpip=localhost:42424"
cookieless="false" timeout="20"/>
在这两个网站。
3)编译和测试站点
4)变成失望,因为它不工作。我从来没有从第二个Web应用程序看到会话。
in both sites.
3) compile and test the site
4) become disappointed because it does not work. I never see the session from the second webapp.
推荐答案
为什么要在应用程序之间共享会话? ASP.NET会话的目的不是要做到这一点。
Why do you want to share Sessions between applications? ASP.NET Session is not designed to do that.
您提出使用相同的ASP.NET状态服务器不工作,因为你的用户将只是获得2个不同的会话令牌,即使同时使用2应用程序从同一台机器,和同一个浏览器的解决方案。您需要考虑如何会话工程,以明白这是为什么。
Your proposed solution of using the same ASP.NET State Server does not work because your user will simply get 2 different session tokens, even if they use your 2 applications concurrently from the same machine, and same browser. You need to consider how Session works to understand why this is.
MSDN :
ASP.NET会话状态使您能够存储和检索的值
用户当用户浏览Web应用程序的ASP.NET页面。 HTTP是
一个无状态的协议。这意味着,在Web服务器将每个HTTP
请求一个页面作为一个独立的请求。服务器不保留
在previous请求中使用的变量值的知识。
ASP.NET会话状态中识别来自同一浏览器的请求
在有限的时间窗口为会话,并提供了一种方法来持续
该会话的持续时间变量的值。
ASP.NET session state enables you to store and retrieve values for a user as the user navigates ASP.NET pages in a Web application. HTTP is a stateless protocol. This means that a Web server treats each HTTP request for a page as an independent request. The server retains no knowledge of variable values that were used during previous requests. ASP.NET session state identifies requests from the same browser during a limited time window as a session, and provides a way to persist variable values for the duration of that session.
ASP.NET Session是用户当前交互的比喻是一个ASP.NET应用程序即可。它存在于ASP.NET给我们来存储用户在使用你的应用程序使得各个页面请求之间的临时状态数据的地方。
ASP.NET Session is a metaphor for a user's current interaction with one ASP.NET application. It exists in ASP.NET to give us a place to store temporary state data between the various page requests that a user makes while using your application.
如果您的应用程序的关系非常密切,如用户在同一时间同时使用,或几乎在同一时间,你可以考虑它们合并成一个单一的ASP.NET应用程序。你可以将它们部署到不同的虚拟目录,以保持一定程度的逻辑分离,但在IIS中只使用一个应用程序。
If your applications are very closely related, e.g. the user uses both at the same time, or almost the same time, you could consider merging them into a single ASP.NET application. You could deploy them into different Virtual Directories to maintain some degree of logical separation, but use only one Application in IIS.
如果您的应用程序不是那么密切相关的,也许他们应该是共享同一个数据库作为一种手段来交换数据,或者例如使用API基于Web服务来交换信息。
If your applications are not that closely related, perhaps they should be sharing the same database as a means to exchange data, or using an API e.g. based on Web Services to exchange information.
这篇关于你可以共享两个.NET 2.0+应用程序之间的会话变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!