6、在Web Server 1上的应用程序中新建一个页面,功能是初始化Session,然后把Session信息序列化,代码如下:
前台代码:
<%...@ Page Language="C#" AutoEventWireup="true" CodeFile="ShareSession.aspx.cs" Inherits="Front_Test_ShareSession"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><title>Session共享</title></head><body><form id="form1" runat="server"><div><asp:Label ID="lHttp_Cookie" runat="server" Text=""></asp:Label><a href="http://localhost:5000/Front/Test/ShareSession.aspx?AUTH_GUID=<%=AUTH_GUID %>">Go Other Web Site(port:5000)</a></div></form></body></html>
后台代码:
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; publicpartialclass Front_Test_ShareSession : System.Web.UI.Page ...{ publicstring AUTH_GUID =""; protectedvoid Page_Load(object sender, EventArgs e) ...{ Session.Clear(); Session.Abandon(); Session.Add("USER_ID", "2002"); Session.Add("USER_NAME", "Xiaojun Liu"); ShareSession.ShareSessionFormatter.Serialize(ShareSession.ShareSessionFormatter.FormatterType.Soap); AUTH_GUID = Session["AUTH_GUID"].ToString(); } }
7、在Web Server 2上进行第5步操作
8、在Web Server 2上的应用程序中新建一个页面,功能是反序列化,还原Session,同时读取Session信息进行测试,代码如下:
前台代码:
<%...@ Page Language="C#" AutoEventWireup="true" CodeFile="ShareSession.aspx.cs" Inherits="Front_Test_ShareSession"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><title>Session共享</title></head><body><form id="form1" runat="server"><div><asp:Label ID="lHttp_Cookie" runat="server" Text=""></asp:Label></div></form></body></html>
后台代码:
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; publicpartialclass Front_Test_ShareSession : System.Web.UI.Page ...{ protectedvoid Page_Load(object sender, EventArgs e) ...{ string guid = Request.Params["AUTH_GUID"].ToString(); ShareSession.ShareSessionFormatter.Deserialize(ShareSession.ShareSessionFormatter.FormatterType.Soap,guid); Response.Write("USER_ID = "+Session["USER_ID"].ToString()+"<br />"); Response.Write("USER_NAME = "+Session["USER_NAME"].ToString()+"<br />"); Response.Write("AUTH_GUID = "+ Session["AUTH_GUID"].ToString() +"<br />"); } }