本文介绍了如何在asp.net中使用Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在asp.net程序中使用cookie..任何人都可以告诉我如何使用吗?

i want to use cookies in asp.net program ..can any body tell me how to use ?

推荐答案



HttpCookie Testcookie = new HttpCookie("CookieName");
//Set cookies value
Testcookie.Value = "CookieValue";
//Set the cookie to expire in 5 minutes
Testcookie.Expires = DateTime.Now.AddMinutes(5);
//Add the cookie in response
Response.Cookies.Add(Testcookie);


检索现有cookie的值


Retrive value of an existing cookie

HttpCookie TestCookie = Request.Cookies["CookieName"];
if (TestCookie!=null)
{
    Response.Write("Cookie values is "+TestCookie.Value.ToString());
}


希望这会有所帮助.


Hope this will be helpful.


这篇关于如何在asp.net中使用Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 11:12