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È»ºóÔÚ¹¹Ôì
Ïà¹ØÎĵµ£º
Page Ö´ÐÐÖн«°´ÕÕÈçÏÂ˳Ðò¼¤»îʼþ£º
Page.PreInit
Page.Init
Page.InitComplite
Page.PreLoad
Page.Load
Page.LoadComplete
Page.PreRender
Page.PreRenderComplete
Èç¹ûÒ³Ãæ´ÓÁîÒ»¸öÒ³Ãæ¼Ì³Ð£¬ÈçBasePage:System.Web.UI.Page£¬ÔÚBasePageÖÐ×öÁËһЩÀ©Õ¹£¬ÈçȨÏÞ¼ì²é£¬¶øÆäËûÒ³Ãæ´ÓBasePage¼Ì³Ð£¬ÔòBasePageºÍ×î ......
HttpWorkerRequest¶ÔÏñÔÚASP.Net´¦ÀíÁ÷³ÌÖеÄλÖãº
ÿһ¸öASP.NET³ÌÐòÖ´ÐÐʱ¶¼»á¶Ôµ±Ç°URLµÄÇëÇó½øÐнâÎö£¬±¾ÎĽ«·ÖÎöASP.NETÒ³ÃæÇëÇóµÄÔÀí¡£µ±ÎÒÃÇÔÚä¯ÀÀÆ÷ÉÏÊäÈëÒ»¸öURLʱ£¬ Á÷³ÌÈçÏ£º
Ê×Ïȱ»WWW·þÎñÆ÷½Ø»ñ£¨inetinfo.exe½ø³Ì£©£¬ ¸Ã½ø³ÌÊ×ÏÈÅжÏÒ³Ãæºó׺£¬ È»ºó¸ù¾ÝIISÖÐÅäÖþö¶¨µ÷ÓþßÌåµÄÀ©Õ¹³ÌÐò¡£
Èçaspx¾Í»áµ ......
1¡£Ê×ÏÈÊÇ»ù±¾ÔÀí£¬±ÈÈç˵ÊÇlife cycle£¬Êý¾Ý¿â²Ù×÷µÈ¡£
2¡£Êµ¼ÊÏîÄ¿µÄʵ¼ù£¬Ç°Ò»½×¶ÎµÄ¹¤×÷ÔÚÕâ¸ö½×¶Î¼ìÑ飬ºÃÏñ×ö¸öÍøվûÓÐÏëÏóµÄÄÇô¼òµ¥¡£
3¡£Ñо¿Êµ¼ÊµÄ°¸ÀýºÍ¿ªÔ´¿ò¼Ü£¬µ½ÕâÀï²ÅÃ÷°×£¬ÔÀ´ÍøÕ¾ÕâôµÄ×öµÄ£¬ºÃÏñÊÇûÓÐÄÇôÄÑ°¡¡£
¼òµ¥µÄдд£¬¼Ç¼ÔÚʵ¼ÊÏîÄ¿ÖеĸÐÎò¡£ÓÚ2010-5-30Íí£¬¾ãÀÖ²¿¡£ ......
·½°¸1£º
/// <summary>
/// ´«ÈëURL·µ»ØÍøÒ³µÄhtml´úÂë
/// </summary>
/// <param name="Url">URL</param>
/// <returns></returns>
public static string getUrltoHtml(string Url)
{
errorMsg = "";
try
{
System.Net.WebRequest wReq = System.Net.WebReque ......