日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

Asp.net跨網站傳遞Session

 趨明 2012-02-16


時間:2011-01-09 09:34來源:未知 作者:admin 點擊:44次
-
-
基本思路:
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)
        {
            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

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

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多