【发布时间】:2011-02-21 12:53:39
【问题描述】:
我正在尝试在托管在同一台服务器上的两个 Web 应用程序之间共享会话。一个是 .net 2.0 Web 表单应用程序,另一个是 .net 3.5 MVC2 应用程序。
两个应用程序的会话设置如下:
<sessionState
mode="StateServer"
stateConnectionString="tcpip=127.0.0.1:42424"
/>
在 webform 应用程序中,我将会话密钥发布到 MVC 应用程序:
protected void LinkButton1_Click(object sender, EventArgs e)
{
Session["myvariable"] = "dan";
string sessionKey = HttpContext.Current.Session.SessionID;
//Followed by some code that posts sessionKey to the other application
}
然后我在 MVC 应用程序中收到它并尝试使用相同的会话,如下所示:
[HttpPost]
public void Recieve(string sessionKey )
{
var manager = new SessionIDManager();
bool redirected;
bool IsAdded;
manager.SaveSessionID(HttpContext.ApplicationInstance.Context, Id, out redirected, out IsAdded);
var myVar = Session["myvariable"];
}
密钥正在发布,但会话似乎没有加载到 MVC 应用程序中,即 sessionKey 为空。我想做的事能做吗?
【问题讨论】:
-
你能把 Session id 发布到其他应用的代码贴出来吗
-
@sotn 评论 (blogs.msdn.microsoft.com/toddca/2007/01/25/…) 中的链接显示了如何使 SQL 会话提供程序为所有应用程序返回相同的应用程序 ID,以便它们有效地共享相同的会话
标签: c# asp.net asp.net-mvc session-state