两个Web应用程序之间的会话共享 [英] Session Sharing between two web applications

查看:289
本文介绍了两个Web应用程序之间的会话共享的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,其中包含两个Web应用程序test1和test2.在test1中,有一个页面webpage1.aspx,我在其中设置了会话["test"] =共享会话";
在test2 Web应用程序中,有一个页面webpage2.aspx,我在该页面中获得了类似于字符串

 str = session [" 测试"].tostring();
它给我错误对象引用,而不是 set 引用对象.

受保护的 无效 Button1_Click1(对象发​​件人,EventArgs e)
         {
             lbl_Msg.Text =会话[" ].ToString();
         }
这里 是我的web.config设置

< sessionState mode = "  stateNetworkTimeout = "  10" stateConnectionString =   tcpip = loopback: 42424" </ > 
    
    <机器钥匙
 validationKey = " " 
 validation = " 
 解密= " /> 

解决方案

会话: http://msdn.microsoft.com/en-us/library /ms178581.aspx [ ^ ]

会话信息不在用户之间共享.这就是整个想法.

即使在同一台计算机上来自同一浏览器实例的两个单独的页面请求,但在不同的选项卡中,也会生成两个单独的会话.这些中的每一个都有自己的一组会话变量.您不能通过会话状态在它们之间共享信息,而没有它们都使用相同的会话-那么您就无法确定响应哪个.这就是会议的全部想法.

如果您希望在两个会话之间共享信息,则需要考虑使用持久性信息,例如两个会话都可以访问的服务器上的数据库.


在两个页面上重新检查代码会话正在使用的位置..

并通过这种方式转换sessin值

str=(string)session["test"];


i have a project which contains two web applications test1 and test2. In test1 there is a page webpage1.aspx where i set the session["test"]="Sharing Session";
and in test2 web application there is a page webpage2.aspx where i get the session like string

str=session["test"].tostring();
it give me error Object reference not set to an instance of an object. 

protected void Button1_Click1(object sender, EventArgs e)
         {
             lbl_Msg.Text = Session["bilawal"].ToString();
         }
Here is my web.config settings

<sessionState mode="StateServer"  stateNetworkTimeout="10" stateConnectionString="tcpip=loopback:42424" ></sessionState>
    
    <machineKey
 validationKey="28648A4880842F28050732A312FF1CDC2F49F66A59422EC9AF062B3135D5064177BA70CF7A4227F497ED6CAFCC91B7970B1746C07867486F43C5D661ADE57B79"
 decryptionKey="92C4163ADB1B5C6D93A0EE8D19C96544CD762DF2472A9DF547DF677AA509BF49"
 validation="SHA1"
 decryption="AES"/>

解决方案

Session: http://msdn.microsoft.com/en-us/library/ms178581.aspx[^]

Session information is not shared between users. That is the whole idea.

Two separate page requests, even from the same browser instance on the same machine, but in different tabs will generate two separate sessions. Each one of these gets it own set of session variables. You cannot share information between them via the Session state without them both using the same session - and then you cannot tell which to respond to. That is the whole idea of sessions.

If you wish to share information between two sessions, then you need to look at using persistent information instead, such as a database on the server which both sessions access.


Recheck your Codes on both pages where session is using..

and do this way to convert sessin values

str=(string)session["test"];


这篇关于两个Web应用程序之间的会话共享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆