小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

Asp.net跨網(wǎng)站傳遞Session

 趨明 2012-02-16


時間:2011-01-09 09:34來源:未知 作者:admin 點擊:44次
-
-
基本思路:
1 Session源網(wǎng)站設置Session數(shù)據(jù)同時,把SessionID和Session數(shù)據(jù)一起插入一個數(shù)據(jù)庫中,再把SessionID作為查詢字符串傳遞到Session獲取網(wǎng)站.
2 Session獲取網(wǎng)站從數(shù)據(jù)庫中按SessionID查詢獲取Session數(shù)據(jù)并賦值到本網(wǎng)站的Session中.

示例:
Session源網(wǎng)站部分:


        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獲取網(wǎng)站部分:


        private void Page_Load(object sender, System.EventArgs e)
        {
            try
            {
                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();
                }
            }
            catch( System.Exception ex )
            {
                this.TextBox1.Text = ex.Message;
            }
        }
 

本篇文章來源于 www. 原文鏈接:http://www./html/aspnet/objects/2011/0109/3338.html

    本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多