在做asp.net开发时,为了存储一些信息,phpstudy常常是Session与Cookie同时使用。Session资料在phpstudy上会找到很多相关的,而Cookie相关的资料相对很少,所以想补充一下。下面是写Cookie的语法:
Response.Cookies[\"曲奇名称\"].Value = \"phpstudy\";
读Cookie的语法:
if (Request.Cookies[\"曲奇名称\"] != null)
{
string cookieValue = Request.Cookies[\"曲奇名称\"].Value.ToString();
}
如果你是在类别中写的话,需要写完整的名称,
写Cookie语法:
System.Web.HttpContext.Current.Response.Cookies[\"曲奇名称\"].Value = \"phpstudy\";
读Cookie语法:
if (System.Web.HttpContext.Current.Request.Cookies[\"曲奇名称\"] != null)
{
string cookieValue = HttpContext.Current.Request.Cookies[\"曲奇名称\"].Value.ToString();
}
本文地址:https://www.stayed.cn/item/1620
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我