ASP.NETÖÐCookieµÄ²Ù×÷
ÔÚѧϰ¹ý³ÌÖÐÐèÒªÓõ½CookieÎļþ£¬ÔÚÍøÉÏÕÒÁËЩÏà¹ØµÄ֪ʶ£¬Ñ§Ï°ÁËÒ»²¿·Ö£¬ÏּǼÈçÏ£º
£¨1£©
HttpCookie myHttpCookie = new HttpCookie("MyWebSite");
DateTime myDateTime = System.DateTime.Now;
TimeSpan myTimeSpan = new TimeSpan();
if (rbHour.Checked == true)
{
myTimeSpan = new TimeSpan(0, 1, 0, 0, 0);
myTime = 0;
}
if (rbDay.Checked == true)
{
myTimeSpan = new TimeSpan(1, 0, 0, 0, 0);
myTime = 1;
}
myHttpCookie.Expires = myDateTime.Add(myTimeSpan);
myHttpCookie.Values.Add("UserName", Server.HtmlEncode(txtUserName.Text.Trim().ToString()));
myHttpCookie.Values.Add("Sex", Server.HtmlEncode(mySex));
myHttpCookie.Values.Add("SelectTime", Server.HtmlEncode(myTime.ToString()));
Response.AppendCookie(myHttpCookie);
Õâ¶Î´úÂëµÄ×÷ÓÃÊÇ´´½¨Ò»¸öÃûΪMyWebSiteµÄCookieÎļþ£¬ÀïÃæÓÐÈýÏ·Ö±ðÊÇUserName£¨Óû§Ãû£©¡¢Sex£¨ÐԱ𣩺ÍSelectTime£¨CookieµÄ¹ýÆÚʱ¼ä£©¡£
£¨2£©
if (Request.Cookies["MyWebSite"] != null)
{
myUserName = Request.Cookies["MyWebSite"]["UserName"].ToString();
mySex = Request.Cookies["MyWebSite"]["Sex"].ToString();
myTime = Request.Cookies["MyWebSite"]["SelectTime"].ToString();
}
if (myUserName != null && mySex != null)
{
HttpCookie myHttpCookie = new HttpCookie("MyWebSite");
if (myHttpCookie != null)
{
myHttpCookie.Values["UserName"] = myUserName.ToString();
myHttpCookie.Values["Sex"] = mySex.ToString();
myHttpCookie.Values["SelectTime"] = myTime.ToString();
DateTime myDateTime=System.DateTime.Now;
if (myTime.ToString() == "0")
{
&nb
Ïà¹ØÎĵµ£º
protected void Button1_Click(object sender, EventArgs e)
{
string strsql = "select * from TreeViewTemp where parentID=0";
DataTable dt = db.GetDataTable(strsql);
StringWriter sw = new StringWriter();
//StreamWriter sw = new Strea ......
Êý¾Ý°ó¶¨ÒÔ¼°Container.DataItemµÄ¾ßÌå·ÖÎö
Áé»îµÄÔËÓÃÊý¾Ý°ó¶¨²Ù×÷
°ó¶¨µ½¼òµ¥ÊôÐÔ:<%#UserName%>
°ó¶¨µ½¼¯ºÏ:<asp:ListBox id="ListBox1" datasource='<%# myArray%>' runat="server">
°ó¶¨µ½±í´ïʽ:<%#(class1.property1.ToString() + "," + class1.property2.ToString())%>
°ó¶¨µ½·½·¨·µ» ......
ASP.NETÒ³ÃæÌøתÓÐʲô·½·¨ÄØ£¿£¬ÏÖÔÚ¸ø´ó¼Ò½éÉÜÈýÖÖ·½·¨£¬ËûÃǵÄÇø±ðÊÇʲôÄØ£¿ÈÃÎÒÃÇ¿ªÊ¼°É£º ASP.NETÒ³ÃæÌøת1¡¢response.redirect Õâ¸öÌøתҳÃæµÄ·½·¨ÌøתµÄËٶȲ»¿ì£¬ÒòΪËüÒª×ß2¸öÀ´»Ø(2´Îpostback)£¬µ«Ëû¿ÉÒÔÌøתµ½ÈκÎÒ³Ã棬ûÓÐÕ¾µãÒ³ÃæÏÞÖÆ(¼´¿ÉÒÔÓÉÑÅ»¢Ìøµ½ÐÂÀË)£¬Í¬Ê±²»ÄÜÌø¹ýµÇ¼±£»¤¡£µ«ËÙ¶ÈÂýÊÇÆä×î´óȱÏÝ!r ......
×òÌìÍíÉÏÓÐÅóÓÑÔÚcsdn£¨Çó¹¤×÷Á÷¿ª·¢×ÊÁÏ £©ÉÏÒª¹ØÓÚ¹¤×÷Á÷µÄ×ÊÁÏ£¬ÕýºÃÇ°¶Îʱ¼äÑо¿Õâ·½ÃæµÄ¶«Î÷£¬ÊÕ¼¯ÁËһЩasp.net·½ÃæµÄ¹¤×÷Á÷×ÊÁÏ£¬ÐÄÏë·´Õý¶¼ÊÇÍøÉÏÀ´µÄºÎ²»Ô츣ϺóÀ´ÈË£¬ÓÚÊÇ°ÑÄÇЩ¾õµÃ»¹¿ÉÒԵĴòÁ˸ö°ü£¬·Åµ½ÎÒ×Ô¼ºµÄ¿Õ¼ä£¨¸ÕÉêÇ뻹ûÕýʽʹÓã©ÉϹ©´ó¼ÒÏÂÔØ.
ÒÔÏÂÊÇ´ó¸ÅµÄĿ¼£¬Ã»Ê±¼äд½éÉÜ£¬¼òµ¥ ......
Ҫʹ ASP.NET Web Ó¦ÓóÌÐòÄܹ»Ê¹Óÿͻ§¶ËÖ¤Ê飬Äú±ØÐëÔÚ±¾µØ¼ÆËã»ú´æ´¢Öа²×°¿Í»§¶ËÖ¤Êé¡£Èç¹ûÄúÔÚ±¾µØ¼ÆËã»ú´æ´¢Öа²×°¿Í»§¶ËÖ¤Ê飬Ôò¸Ã¿Í»§¶ËÖ¤Êé½ö¶Ô¹ÜÀíÔ±×éÖеÄÓû§ÕÊ»§ºÍ°²×°¸Ã¿Í»§¶ËÖ¤ÊéµÄÓû§¿ÉÓá£Òò´Ë£¬Äú±ØÐëÏòÓÃÓÚÔËÐÐ ASP.NET Web Ó¦ÓóÌÐòµÄÓû§ÕÊ»§ÊÚȨ£¬Ê¹ÆäÄܹ»·ÃÎÊ¿Í»§¶ËÖ¤Êé¡£
×¢Ò⣺±ØÐë°²×° Microso ......