基本思路:
1 Session源網站設定Session資料同時,把SessionID和Session資料一起插入一個資料庫中,再把SessionID作為查詢字元串傳遞到Session擷取網站.
2 Session擷取網站從資料庫中按SessionID查詢擷取Session資料并指派到本網站的Session中.
示例:
Session源網站部分:

private void Button1_Click(object sender, System.EventArgs e)
{
try
this.TextBox1.Text = Session.SessionID;
Session["Name"] = this.TextBox2.Text;
Session["Role"] = this.TextBox3.Text;
OleDbConnection conn = new OleDbConnection( @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\webTest.mdb;Persist Security Info=False" );
string strInsertSql = "insert into SessionData "
+ " ( SessionID, SessionName, SessionRole ) "
+ " values "
+ "( '" + Session.SessionID + "', '" + Session["Name"] + "', '" + Session["Role"] + "' )";
conn.Open();
OleDbCommand cmd = new OleDbCommand( strInsertSql, conn );
cmd.ExecuteNonQuery();
conn.Close();
this.TextBox1.Text = "Session儲存成功";
string strJumpUrl = "http://localhost/SessionReadFromOtherSite/ReadOtherSession.aspx?SessionId=" + Session.SessionID;
Response.Write("<script>window.open('" + strJumpUrl + "');</script>");
}
catch( System.Exception ex )
this.TextBox1.Text = ex.Message;
}
}
Session擷取網站部分:

private void Page_Load(object sender, System.EventArgs e)
if ( Request.QueryString["SessionID"] != null )
OleDbConnection conn = new OleDbConnection( @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\webTest.mdb;Persist Security Info=False" );
string strSql = "select "
+ " SessionID, SessionName, SessionRole "
+ " from SessionData "
+ " where SessionID = '" + Request.QueryString["SessionID"].ToString() + "'";
OleDbDataAdapter da = new OleDbDataAdapter( strSql, conn );
DataSet ds = new DataSet();
da.Fill( ds );
Session["Name"] = ds.Tables[0].Rows[0]["SessionName"].ToString();
Session["Role"] = ds.Tables[0].Rows[0]["SessionRole"].ToString();
this.TextBox1.Text = ds.Tables[0].Rows[0]["SessionID"].ToString();
this.TextBox2.Text = Session["Name"].ToString();
this.TextBox3.Text = Session["Role"].ToString();
}