ASP.NET 2.0ÍøÕ¾ÓÅ»¯¼¼ÇÉ×ܽá
1. µ±²»ÐèҪʹÓÃSessionµÄʱºòÇë¹Ø±Õ
¹Ø±ÕSessionµ±²»ÐèҪʹÓõÄʱºò
• ÈôÒª½ûÓÃÒ³µÄ»á»°×´Ì¬£¬Ç뽫@ Page Ö¸ÁîÖеÄEnableSessionState ÊôÐÔÉèÖÃΪfalse¡£ÀýÈ磬 <%@ Page EnableSessionState="false" %>¡£
• ×¢ÒâÈç¹ûÒ³ÐèÒª·ÃÎʻỰ±äÁ¿£¬µ«²»´òËã´´½¨»òÐÞ¸ÄËüÃÇ£¬Ôò½«@ Page Ö¸ÁîÖеÄEnableSessionState ÊôÐÔÉèÖÃΪReadOnly¡£»¹¿ÉÒÔ½ûÓÃXML Web services ·½·¨µÄ»á»°×´Ì¬¡£Óйظü¶àÐÅÏ¢£¬Çë²Î¼ûʹÓÃASP.NET ºÍXML Web services ¿Í»§¶Ë´´½¨µÄXML Web services¡£
• ÈôÒª½ûÓÃÓ¦ÓóÌÐòµÄ»á»°×´Ì¬£¬ÇëÔÚÓ¦ÓóÌÐòWeb.config ÎļþµÄsessionstate ÅäÖýÚÖн«mode ÊôÐÔÉèÖÃΪoff¡£ÀýÈ磬 <sessionstate mode="off" />¡£
2.¾¡Á¿Ê¹Óÿͻ§¶Ë½Å±¾
ËäÈ»ÄúºÜ¿ÉÄÜÏ£Íû¾¡Á¿¶àµØʹÓÃWeb ´°ÌåÒ³¿ò¼ÜµÄÄÇЩ½Úʡʱ¼äºÍ´úÂëµÄ¹¦ÄÜ£¬µ«ÔÚijЩÇé¿öÏÂÈ´²»ÒËʹÓÃASP.NET ·þÎñÆ÷¿Ø¼þºÍ»Ø·¢Ê¼þ´¦Àí¡£Í¨³££¬Ö»ÓÐÔÚ¼ìË÷»ò´æ´¢Êý¾Ýʱ£¬Äú²ÅÐèÒªÆô¶¯µ½·þÎñÆ÷µÄÍù·µ¹ý³Ì¡£¶àÊýÊý¾Ý²Ù×÷¿ÉÔÚÕâЩÍù·µ¹ý³Ì¼äµÄ¿Í»§¶ËÉϽøÐС£ÀýÈ磬´ÓHTML´°ÌåÑéÖ¤Óû§ÊäÈë¾³£¿ÉÔÚÊý¾ÝÌá½»µ½·þÎñÆ÷֮ǰÔÚ¿Í»§¶Ë½øÐС£Í¨³££¬Èç¹û²»ÐèÒª½«ÐÅÏ¢´«µÝµ½·þÎñÆ÷ÒÔ½«Æä´æ´¢ÔÚÊý¾Ý¿âÖУ¬ÄÇôÄú²»Ó¦¸Ã±àдµ¼ÖÂÍù·µ¹ý³ÌµÄ´úÂë¡£
3.ʹÓÃPage.IsPostback±ÜÃâ¶ÔÍù·µ¹ý³ÌÖ´Ðв»±ØÒªµÄ´¦Àí
• Èç¹ûÄú±àд´¦Àí·þÎñÆ÷¿Ø¼þ»Ø·¢´¦ÀíµÄ´úÂ룬ÓÐʱ¿ÉÄÜÐèÒªÔÚÊ×´ÎÇëÇóҳʱִÐÐÆäËû´úÂ룬¶ø²»Êǵ±Óû§·¢ËÍ°üº¬ÔÚ¸ÃÒ³ÖеÄHTML ´°ÌåʱִÐеĴúÂë¡£¸ù¾Ý¸ÃÒ³ÊÇ·ñÊÇÏìÓ¦·þÎñÆ÷¿Ø¼þʼþÉú³ÉµÄ£¬Ê¹ÓÃPage.IsPostBack ÊôÐÔÓÐÌõ¼þµØÖ´ÐдúÂë¡£
• ×¢ÒâÈç¹û²»ÔËÐÐÕâÖÖ¼ì²é£¬»Ø·¢Ò³µÄÐÐΪ½«²»¸ü¸Ä¡£Page_Load ʼþµÄ´úÂëÔÚÖ´ÐзþÎñÆ÷¿Ø¼þʼþ֮ǰִÐУ¬µ«Ö»ÓзþÎñÆ÷¿Ø¼þʼþµÄ½á¹û²Å¿ÉÄÜÔÚÊä³öÒ³ÉϳÊÏÖ¡£Èç¹û²»ÔËÐиüì²é£¬ÈÔ½«ÎªPage_Load ʼþºÍ¸ÃÒ³ÉϵÄÈκηþÎñÆ÷¿Ø¼þʼþÖ´Ðд¦Àí¡£
4.ÔÚÊʵ±µÄ»·¾³ÖÐʹÓÃASP.NET ·þÎñÆ÷¿Ø¼þ
¼ì²éÄúµÄÓ¦ÓóÌÐò´úÂëÒÔÈ·±£¶ÔASP.NET·þÎñÆ÷¿Ø¼þµÄʹÓÃÊDZØÒªµÄ¡£¼´Ê¹ËüÃǷdz£Ò×ÓÚʹÓ㬵«ÊÇ·þÎñÆ÷¿Ø¼þ²¢²»×ÜÊÇÍê³ÉÈÎÎñµÄ×î¼ÑÑ¡Ôñ£¬ÒòΪËüÃÇ»áʹÓ÷þÎñÆ÷×ÊÔ´¡£ÔÚÐí¶àÇé¿öÏ£¬Ò»¸ö¼òµ¥µÄ³ÊÏÖ»òÊý¾Ý°ó¶¨´úÈë¾Í¿ÉÒÔÍê³ÉÈÎÎñ¡£
5.Ö»ÔÚ±ØҪʱ±£´æ·þÎñÆ÷¿Ø¼þÊÓͼ״̬
• ×Ô¶¯ÊÓͼ״̬¹ÜÀíÊÇ·þÎñÆ÷¿Ø¼þµÄ¹¦ÄÜ£¬¸Ã¹¦ÄÜʹ·þÎñÆ÷¿Ø¼þ¿ÉÒÔÔÚÍù·µ¹ý³ÌÉÏÖØÐÂÌî³äËüÃ
Ïà¹ØÎĵµ£º
package com.accp.filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.H ......
ÔÚÔçÆÚѧϰc#µÄ¹ý³ÌÖУ¬¾³£Óöµ½ÕâÑùµÄÓï¾ä£º
public string StudentName
{
get{return stuName;}
set{stuName=value;}
}
µ±Ê±Ò²²»ÊǺÜÃ÷°×ΪʲôҪÕâÑù£¿Ñ§ÉîÁËc#ºó£ ......
µÚÒ»ÖÖ·½·¨£º
ͨ¹ýURLÁ´½ÓµØÖ·´«µÝ
send.aspx:
protected void Button1_Click(object sender, EventArgs e)
{
Request.Redirect("Default2.aspx?username=honge");
}
receive.aspx:
string user ......
¿Í»§¶ËÑéÖ¤·½Ê½£º
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
&nbs ......