»áÔ±£º ÃÜÂ룺 ¡¡Ãâ·Ñ×¢²á | Íü¼ÇÃÜÂë | »áÔ±µÇ¼ ÍøÒ³¹¦ÄÜ£º ¼ÓÈëÊÕ²Ø ÉèΪÊ×Ò³ ÍøÕ¾ËÑË÷  
 °²È«¼¼Êõ¼¼ÊõÎĵµ
  ¡¤ °²È«ÅäÖÆ
  ¡¤ ¹¤¾ß½éÉÜ
  ¡¤ ºÚ¿Í½Ìѧ
  ¡¤ ·À»ðǽ
  ¡¤ Â©¶´·ÖÎö
  ¡¤ ÆƽâרÌâ
  ¡¤ ºÚ¿Í±à³Ì
  ¡¤ ÈëÇÖ¼ì²â
 °²È«¼¼ÊõÂÛ̳
  ¡¤ °²È«ÅäÖÆ
  ¡¤ ¹¤¾ß½éÉÜ
  ¡¤ ·À»ðǽ
  ¡¤ ºÚ¿ÍÈëÇÖ
  ¡¤ Â©¶´¼ì²â
  ¡¤ Æƽⷽ·¨
  ¡¤ É±¶¾×¨Çø
 °²È«¼¼Êõ¹¤¾ßÏÂÔØ
  ¡¤ É¨Ã蹤¾ß
  ¡¤ ¹¥»÷³ÌÐò
  ¡¤ ºóÃÅľÂí
  ¡¤ ¾Ü¾ø·þÎñ
  ¡¤ ¿ÚÁîÆƽâ
  ¡¤ ´úÀí³ÌÐò
  ¡¤ ·À»ðǽ
  ¡¤ ¼ÓÃܽâÃÜ
  ¡¤ ÈëÇÖ¼ì²â
  ¡¤ ¹¥·ÀÑÝʾ
¼¼ÊõÎĵµ > Web¿ª·¢ > ASP.Net
Ç×ÃܽӴ¥ASP.Net(15)
·¢±íÈÕÆÚ£º2003-06-26 00:00:00×÷Õߣº· ³ö´¦£º  

ASP.NetÖÐ״̬±£´æ

ÔÚASP±£´æһЩ¹²Ïí¡¢¸öÈË״̬£¬Ê¹ÓõÄÊÇApplication¡¢Session¡¢CookieÕâÈýÖÖ¡£ºÇºÇ¡£ÔÚASP.NetÖÐM$³ýÁ˼̳ÐApplicationµÈÍ⣬ÓÖ¸øÎÒÃÇеÄÒ»ÖÖ״̬±äÁ¿ÐÅÏ¢State£¬ËüÊÇÓÃÀ´±£´æWEB¿Ø¼þµÄ״̬µÄ±äÁ¿£¬ºÜÐÂÏÊ°É£¬Ò»¶¨Òª¿ìµãÖªµÀÀ²£º£©

²»ºÃÒâ˼£¬·Éµ¶»¹ÊÇ´Óԭʼһ²½²½À´Ëµ°É¡£ÏÈ´ÓApplication½²Æð¡£(̨ÏÂһƬºðÉù)£¬Ã»Óа취£¬ÎªÁËÓиö½×ÌÝÐÔ£¬»¹ÊDz»Ó¦µ±¹ýÔç½Ó´¥Ð¶«¶«À²£º£©

Application

ÔÚASP.NetÖÐApplicationÓ÷¨ÓëASPÊÇÒ»ÑùµÄ£¬¼¸ºõÊÇûÓÐʲô˵µÄ£¬µ«ÊÇËü¶àÁËÁ½¸öÌرðÓÐÓõÄʼþ£¬Application_OnBeginRequestºÍApplication_OnEndRequest¡£ËûÃǵĺÍÔ­À´µÄApplication_OnStartºÍApplication_OnEndÒ»ÑùÊÇ·ÅÔÚglobalÎļþÖеÄ(×¢ÒâÕâ¸öÎļþÔÚASPÖÐÃû×ÖÊÇglobal.asa£¬ÔÚASP.NetÖÐÊÇglobal.asax)¡£

×¢£ºÕâ¸öʼþ£¬Ð´²»Ð´OnÊÇÒ»ÑùµÄ¡£ÈçApplication_EndÓëApplication_OnEndÊÇÒ»ÑùµÄ

Application_OnStartÊÇÔÚÕû¸öASP.NetÓ¦ÓÃÊ×Ïȱ»´¥·¢µÄʼþ£¬Ò²¾ÍÊÇÔÚÒ»¸öÐéÄâĿ¼ÖеÚÒ»¸öASP.Net³ÌÐòÖ´ÐÐʱ´¥·¢£¬Application_OnEnd¾ÍÕýºÃÏà·´£¬ÔÚÕû¸öÓ¦ÓÃֹͣʱ±»´¥·¢£¨Í¨³£·¢ÉúÔÚ·þÎñÆ÷±»ÖØÆô/¹Ø»úʱ)¡£Application_OnRequestStartºÍApplication_OnRequestEndÔòÊÇÔÚÿһ¸öASP.Net³ÌÐò±»ÇëÇóʱ¾Í·¢Éú£¬Ò²¾ÍÊÇ˵¿Í»§·ÃÎÊÒ»´ÎÒ»¸öASP.Net³ÌÐò£¬ÕâÁ½¸öʼþ¾Í»á±»´¥·¢¡£ÎÒÃÇ¿ÉÒÔ´ÓÏÂÃæµÄ³ÌÐò¿´µ½ËûµÄÓ¦ÓÃ.ÎÒÃÇÏȽ¨Á¢Ò»¸öglobal.asax,ÄÚÈÝÈçÏ£º

<script language="C#" runat="server">

  void Application_OnBeginRequest(Object sender, EventArgs E)

  {

    Response.Write("Request is Starting...<br>");

  }

  void Application_OnEndRequest(Object sender, EventArgs E)

  {

    Response.Write("Request is Ending...<br>");

  }

</script>

È»ºó½«Æä·Åµ½±¾ÐéÄâĿ¼µÄ¸ùĿ¼ÏÂ,È»ºóÎÒÃÇËæ±ã´ò¿ªÒ»¸öʲôaspxÎļþ£¬ÕâÀïÎÒÃÇ´ò¿ªnamed.aspxÎļþ£¬¿´¿´:

ͼ15-1

¿´µ½Ã»ÓУ¬Õâ¸öÒ³ÃæµÄÉÏÃæºÍÏÂÃæ³öÏÖÁËÎÒÃÇÔÚglobal.asaxÖж¨ÒåµÄÓï¾äRequest is Starting...ºÍRequest is Ending...Õâ¸ö²»ÊÇÎÒÃÇÔÚÕâ¸öÎļþÖжÀ¼ÓµÄ£¬ÎÒÃǽ«»áÔÙÈκÎÒ»¸öASP.NetÎļþÖп´µ½ËüµÄÓ°×Ó¡£

Session

ASP.NetÖеÄSessionÊÇÎÒ¼û¹ý×îºÃµÄ´¦Àí£¬ÊÇÆäËü¶¯Ì¬ÍøÒ³¼¼Êõ²»ÄܱÈÄâµÄ¡£ASP.NetÖеÄSessionÔÙÒ²²»ÐèÒªCookiesµÄÖ§³Ö£¬Ò²¾ÍÊÇ˵Èç¹ûÓû§¹Ø±ÕÁËCookie£¬SessionµÄÖµÒ»ÑùÒ²¿ÉÒÔ±»±£´æ¡£

²»¹ý£¬ÎÒÃÇÐèÒª¶Ôconfig.webÎļþ½øÐÐһЩÅäÖÆ£¬ÒòΪÔÚÆäÖÐÕÒµ½¹ØÓÚSessionµÄÉèÖÃÎı¾£¬Èç:

<sessionstate

cookieless="false"

/>

°Ñcookieless="false" ¸Ä³Écookieless="true" £¬ÄÇôÒÔºóSession¾Í²»´¢´æÔÚcookiesÖÐÁË£¬¶øÔÚ´¢´æÔÚURLÖС£

ͼ15-2

ÉÏÃæµÄºÚȦÖеĶ«¶«¾ÍÊÇ´¢´æµÄSessionÖµ£¬µ±È»ÕâÊDZ»±àÂëµÄ£¬ÎÒÃÇÎÞ·¨ÖªµÀËüµÄֱʵֵ¡£

Æäʵ£¬ÎÒ·¢ÏÖ£¬²»ÓøÄconfig.webÎļþ£¬¹Øµôcookiesºó£¬²»ÓÃURLÒ²ÕÕÑùÄÜ´«µÝsessionÖµ£¬ÕâÖÖÇé¿öÏÂSessionÊÇÈçºÎ±£ÖµµÄ£¬Õâ¸ö¾Í²»Ì«Çå³þÁË£º£©

Session»¹¿É±£³Ö²»ËÀÖ®Êõ£¬¾ÍÊǵ±·þÎñÆ÷ÖØÆô£¬»¹ÊÇÄܱ£Ö¤SessionÖеÄÖµ²»±ä£¬²»¹ýÕâÓÖÒª¸Ä¶¯config.webÎļþ¡£Ò²ÊÇͨ¹ýÏÂÃæµÄÓï¾äÉ趨.

<sessionstate

inproc="false"

server="localhost"

port="42424"

/>

ÊDz»ÊÇ·¢ÏÖÕâÀïµÄSessionÊDz»ÊǺÜÇ¿´ó°¡£º£©£¬°Ñlocalhost¸Ä³ÉÄúÒªµÄÖ÷»ú£¬Session»¹ÄÜÔÚÁíÍâһ̨Ö÷»úÉϱ£³Ö¡£

¡¾·µ»Ø¶¥²¿¡¿ ¡¾´òÓ¡±¾Ò³¡¿ ¡¾¹Ø±Õ´°¿Ú¡¿

¹ØÓÚÎÒÃÇ / ¸øÎÒÁôÑÔ / °æȨ¾Ù±¨ / Òâ¼û½¨Òé / ÍøÕ¾±à³ÌQQȺ   
Copyright ©2003- 2024 Lihuasoft.net webmaster(at)lihuasoft.net ¼ÓÔØʱ¼ä 0.00175