ASP.NET CookieʹÓÃ(ת)
1.ʲôÊÇcookie?
cookie ÊÇһС¶ÎÎı¾ÐÅÏ¢£¬°éËæÓû§ÇëÇó£¬ÔÚweb·þÎñÆ÷ºÍä¯ÀÀÆ÷Ö®¼ä´«µÝ¡£Óû§Ã¿´Î·ÃÎÊÕ¾µãµÄʱºò£¬
webÓ¦ÓóÌÐò¶¼¿ÉÒÔ¶ÁÈ¡cookie°üº¬µÄÐÅÏ¢¡£
¼ÙÉèÔÚÓû§ÇëÇóÄúµÄÍøÕ¾µÄij¸öÒ³Ãæʱ£¬ÄúµÄÓ¦ÓóÌÐò²»½öÊÇ·µ»ØÇëÇóµÄÒ³Ã档ͬʱҲ·µ»ØÒ»¸ö°üº¬ÈÕÆÚ
ºÍʱ¼äµÄcookie¡£Óû§µÄä¯ÀÀÆ÷ÔÚ»ñµÃÒ³ÃæµÄͬʱҲ»ñµÃÁËcookie.²¢ÇÒcookie±£´æÔÚ¿Í»§¶ËµÄcookieÎÄ
¼þ¼ÐÖС£
2.cookie µÄÏÞÖÆ
´ó¶àÊýä¯ÀÀÆ÷Ö§³Ö×î¶à¿É´ï4096×Ö½Ú£¨´óÔ¼4KB£©cookie.ä¯ÀÀÆ÷»¹ÏÞÖÆÁË£¬Ò»¸öÕ¾µã¿ÉÒÔÔÚ¿Í»§¶Ë±£´æ
cookieÊý¡£´ó¶àÊýä¯ÀÀÆ÷ÔÊÐíÿ¸öÕ¾µã×î¶à·Å20¸öcookie.Èç¹ûÊÔͼ±£´æ¸ü¶àµÄcookie,ÄÇôÏÈÇ°µÄcookie
½«±»É¾³ý¡£»¹ÓÐЩä¯ÀÀÆ÷»á¶ÔÀ´×ÔËùÓÐÕ¾µãcookie×ÜÊýÏÞÖÆ£¬Õâ¸öÏÞÖÆͨ³£Îª300¸ö¡£
3.cookie ÈçºÎ´´½¨
ÔÚ´´½¨cookieµÄʱºòÒªÖ¸¶¨¼¸¸öÖµ¡£×î³õ£¬ÄúÒªÖ¸¶¨cookieµÄÃû×ÖºÍÒª±£´æµÄÖµ¡£ÄúÒ²¿ÉÒÔ´´½¨¶à¸ö
cookie¡£µ«Ã¿¸öcookieµÄÃû×Ö±ØÐëΨһ£¬ÒÔ±ãÈÕºóȡֵʱʶ±ð¡££¨cookieÊÇ°´Ãû×Ö´¢´æµÄ£¬ËùÒÔÄúÒª´´½¨
Á½¸öÃû³ÆÏàͬµÄcookie£¬ÄÇô×îºóÄǸöcookie½«¸²¸ÇÇ°Ò»¸ö¡££©
ÄúÒ²¿ÉÒÔ¸øcookieÖ¸¶¨¹ýÆÚÈÕÆÚºÍʱ¼ä.cookieÊÇдÈëµ½Óû§Ó²ÅÌÉϵģ¬È»ºó¿ÉÄÜÒ»Ö±¶¼ÁôÔÚ´ÅÅÌÉÏ¡£Òò
´Ë£¬Äú¿ÉÒÔÖ¸¶¨cookieµÄ¹ýÆÚÈÕÆÚºÍʱ¼ä¡£µ±Óû§Ï´ηÃÎÊÄúµÄÕ¾µãµÄʱºò£¬ä¯ÀÀÆ÷»áÏȼì²éÄúÕ¾µãµÄËù
ÓÐcookie,Èç¹ûij¸öcookieÒѾ¹ýÆÚ£¬ä¯ÀÀÆ÷²»»á°ÑÕâ¸öcookieËæÒ³ÃæÇëÇóÒ»Æð·¢Ë͸ø·þÎñÆ÷£¬¶øÊÇɾ³ý
Õâ¸öÒѾ¹ýÆÚµÄcookie.(ÄúµÄÕ¾µã¿ÉÄÜÒѾÔÚÓû§´ÅÅÌÉÏдÈë¶à¸öcookie¡£µ«¸öÿ¸öcookieµÄ¹ýÆÚÈÕÆÚºÍ
ʱ¼ä²»Í¬)¡£ä¯ÀÀÆ÷¸ºÔð´ÅÅÌÉϵÄcookie,Õ⽫ӰÏìÄúµÄÓ¦ÓóÌÐò¶ÔcookieµÄʹÓÃ
Èç¹ûûÓÐÉèÖÃcookieµÄÓÐЧʱ¼ä,»¹ÊÇ¿ÉÒÔ´´½¨cookie£¨ÎÒÃdzÆ×ö»á»°cookie£©,»á»°cookie²»»á±£´æµ½´Å
ÅÌÉÏ£¬¶øÊDZ£´æÔÚÄÚ´æÖС£³ÉΪÓû§»á»°ÐÅÏ¢µÄÒ»²¿·Ö¡£Èç¹ûÓû§¹Ø±Õä¯ÀÀÆ÷»òÕ߻Ự³¬Ê±£¬¸Ãcookie½«
±»É¾³ý¡£ÕâÖÖ·ÇÓÀ¾ÃÐÔµÄcookie.
4.cookie ÖеĴ´½¨·½·¨
Äú¿ÉÒÔͨ¹ý¶àÖÖ·½·¨´´½¨cookieÈ»ºó°Ñcookie¶ÔÏó·Åµ½Response.Cookies¼¯ºÏÖС£ËæÇëÇóÒ³ÃæÒ»Æ𷵻ظø
ä¯ÀÀÆ÷¡£
µÚÒ»ÖÖ:
Response.Cookies("cookiename").Value="aaaa"; //´´½¨Ò»¸öÃû×ÖΪcookienameµÄcookie.È»ºóÔÚcookie
Öд洢µÄֵΪaaaa
Response.Cookies("cookiename").Expires=DateTime.Now.AddDays(1);//Ö¸¶¨cookieµÄ¹ýÆÚʱ¼äΪ1Ìì
µÚ¶þÖÖ£º
HttpCookie acookie=new HttpCookie(cookiename);//HttpCookieÀà´´½¨cookieÈ»ºóÔÚ¹¹Ôì
Ïà¹ØÎĵµ£º
ASP.NETÊÇÒ»¸ö·Ç³£Ç¿´óµÄ¹¹½¨WebÓ¦ÓõÄƽ̨£¬ËüÌṩÁ˼«´óµÄÁé»îÐÔºÍÄÜÁ¦ÒÔÖÂÓÚ¿ÉÒÔÓÃËüÀ´¹¹½¨ËùÓÐÀàÐ͵ÄWebÓ¦Óá£
¾ø´ó¶àÊýµÄÈËÖ»ÊìϤ¸ß²ãµÄ¿ò¼ÜÈ磺 WebForms ºÍ WebServices --ÕâЩ¶¼ÔÚASP.NET²ã´Î½á¹¹ÔÚ×î¸ß²ã¡£
ÕâƪÎÄÕµÄ×ÊÁÏÊÕ¼¯ÕûÀí×Ô¸÷ÖÖ΢Èí¹«¿ªµÄÎĵµ£¬Í¨¹ý±È½Ï IIS5¡¢IIS6¡¢IIS7 ÕâÈý´ú IIS ¶ÔÇëÇóµÄ´¦Àí¹ý³ ......
1¡¢Ö±½ÓÔÚǰ̨µ÷Óà javascript º¯Êý
ºÜ¼òµ¥,ÔÚ head ÔªËØÖ®¼ä¼ÓÈë script ÔªËØ,½« type ÔªËØÉèÖÃΪ " text/javascript "
Èç:
¸´ÖÆ´úÂë ´úÂëÈçÏÂ:
<head runat="server">
<script type="text/javascript" >
function ShowName(str)
{
alert("ÄúµÄÃû×ÖΪ:("+s ......
Web ÊÇ»ùÓÚÎÞ״̬µÄhttpÐÒ飬ASP.NET ΪÁ˱£Ö¤¿Ø¼þÔÚÒ³Ãæ´«Ë͵½·þÎñÆ÷£¬ÔÙ´Ó·þÎñÆ÷·¢»Øµ½Ò³ÃæµÄʱ±£³Ö֮ǰµÄ״̬¡£
´úÂë×¼±¸£º
ÔÚaspxÒ³ÃæÉÏÌí¼ÓÒ»¸ölistbox¿Ø¼þ£¬ºÍÒ»¸öbutton·þÎñÆ÷¿Ø¼þ£º
<
asp:ListBox runat
=
"
server
"
ID
=
"
lbViewState
"
></
asp ......
ÒÔÏÂÄÚÈÝ,´ÔÍøÉÏCOPY¹ýÀ´µÄ...
ApacheÊÇÄ¿Ç°¹ã·ºÊ¹ÓõÄÒ»ÖÖÍøÂç·þÎñÆ÷³ÌÐò£¬²»½öÔÚUNIX/LINUXƽ̨Éϱ»´óÁ¿Ê¹Ó㬶øÇÒÔÚWindowsƽ̨ÉÏÒ²ÓÐÐí¶àÕ¾µã·ÅÆúÁËIIS¶øתÏòApache¡£.NETÊÇ΢ÈíÍƳöµÄ¹¦ÄÜÇ¿´óµÄ¿ª·¢¼¼Êõ£¬ÆäÄ¿±ê¾ÍÊÇÓëJava¿¹ºâ¡£ASP.NET·Ç³£ÊʺÏÓÚÖÐСÆóÒµµÄWebÓ¦Óã¬ÆäÐÔÄܽÏASP3.0ÓÐÁ˼«´óµÄÌá¸ß¡£ÏÂÃæ¾Í½éÉÜÈÃAp ......
ÎÊÌâÃèÊö£º
Asp.NetÖÐdatalistµÈweb¿Ø¼þÀïÃ棬·Å¶à¸öµ¥Ñ¡°´Å¥µÄʱºò¿ÉÒÔͬʱ¶àÑ¡¡£
ÎÊÌâ½â¾ö£º
×îÀíÏëµÄ½â¾öÖ®µÀ£¬ÓÃjavascript£º
<script language="javascript" type="text/javascript">
function clickit() {
var dom=document.all;
& ......