ASp.NET½Ì³Ì:Ò³Ãæ´«ÖµµÄÎåÖÖ·½·¨(2)

http://www.itjxue.com  2015-07-17 01:58  À´Ô´:δ֪  µã»÷´ÎÊý: 

3.  ʹÓÃSession±äÁ¿

Ïë±ØÕâ¸ö¿Ï¶¨ÊÇ´ó¼ÒʹÓÃÖÐ×î³£¼ûµÄÓ÷¨ÁË£¬Æä²Ù×÷ÓëApplicationÀàËÆ£¬×÷ÓÃÓÚÓû§¸öÈË£¬ËùÒÔ£¬¹ýÁ¿µÄ´æ´¢»áµ¼Ö·þÎñÆ÷ÄÚ´æ×ÊÔ´µÄºÄ¾¡¡£

a.aspxµÄC#´úÂë

private void Button1_Click(object sender, System.EventArgs e)
{
    Session["name"] = Label.Text;
}

b.aspxÖÐC#´úÂë

private void Page_Load(object sender, EventArgs e)
{
    string name;
    name = Session["name"].ToString();
}

4.  ʹÓÃCookie¶ÔÏó±äÁ¿

Õâ¸öÒ²ÊÇ´ó¼Ò³£Ê¹Óõķ½·¨£¬ÓëSessionÒ»Ñù£¬ÆäÊÇʲ¶Ôÿһ¸öÓû§¶øÑԵģ¬µ«ÊÇÓиö±¾ÖʵÄÇø±ð£¬¼´CookieÊÇ´æ·ÅÔÚ¿Í»§¶ËµÄ£¬¶øsessionÊÇ´æ·ÅÔÚ·þÎñÆ÷¶ËµÄ¡£¶øÇÒCookieµÄʹÓÃÒªÅäºÏASP.NETÄÚÖöÔÏóRequestÀ´Ê¹Óá£

a.aspxµÄC#´úÂë

private void Button1_Click(object sender, System.EventArgs e)
{
    HttpCookie cookie_name = new HttpCookie("name");
    cookie_name.Value = Label1.Text;
    Reponse.AppendCookie(cookie_name);
    Server.Transfer("b.aspx");
}

b.aspxÖÐC#´úÂë

private void Page_Load(object sender, EventArgs e)
{
    string name;
    name = Request.Cookie["name"].Value.ToString();
}

5.  ʹÓÃServer.Transfer·½·¨

Õâ¸ö²Å¿ÉÒÔ˵ÊÇÃæÏó¶ÔÏ󿪷¢ËùʹÓõķ½·¨£¬ÆäʹÓÃServer.Transfer·½·¨°ÑÁ÷³Ì´Óµ±Ç°Ò³ÃæÒýµ¼µ½ÁíÒ»¸öÒ³ÃæÖУ¬ÐµÄÒ³ÃæʹÓÃÇ°Ò»¸öÒ³ÃæµÄÓ¦´ðÁ÷£¬ËùÒÔÕâ¸ö·½·¨ÊÇÍêÈ«ÃæÏó¶ÔÏóµÄ£¬¼ò½àÓÐЧ¡£

a.aspxµÄC#´úÂë

public string Name
{
    get{ return Label1.Text;}
}
private void Button1_Click(object sender, System.EventArgs e)
{
    Server.Transfer("b.aspx");
}

b.aspxÖÐC#´úÂë

private void Page_Load(object sender, EventArgs e)
{
    a newWeb;   //ʵÀýa´°Ìå
    newWeb = (source)Context.Handler;
    string name;
    name = newWeb.Name;
}

(ÔðÈα༭£ºIT½ÌѧÍø)

¸ü¶à

ÍƼöASP.NET½Ì³ÌÎÄÕÂ