相关疑难解决方法(0)

使用ASP.NET会话状态服务跨应用程序共享会话

我正在尝试在两个Web应用程序之间共享会话,这两个Web应用程序都托管在同一台服 一个是.net 2.0 Web表单应用程序,另一个是.net 3.5 MVC2应用程序.

两个应用程序的会话都设置如下:

<sessionState
      mode="StateServer"
      stateConnectionString="tcpip=127.0.0.1:42424"
      />
Run Code Online (Sandbox Code Playgroud)

在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    
}
Run Code Online (Sandbox Code Playgroud)

然后我在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"];

}
Run Code Online (Sandbox Code Playgroud)

密钥正在发布但会话似乎没有加载到MVC应用程序中,即sessionKey为null.可以做我想做的事吗?

c# asp.net asp.net-mvc session-state

48
推荐指数
2
解决办法
7万
查看次数

标签 统计

asp.net ×1

asp.net-mvc ×1

c# ×1

session-state ×1