手记

在Asp.net网页上写读Cookie

在做asp.net开发时,为了存储一些信息,Insus.NET常常是Session与Cookie同时使用。Session资料在Insus.NET博客上会找到很多相关的,而Cookie相关的资料相对很少,所以想补充一下。下面是写Cookie的语法:

Response.Cookies["曲奇名称"].Value = "Insus.NET";

 

读Cookie的语法:

if (Request.Cookies["曲奇名称"] != null)
{
    string cookieValue = Request.Cookies["曲奇名称"].Value.ToString();
}


如果你是在类别中写的话,需要写完整的名称,

写Cookie语法:

System.Web.HttpContext.Current.Response.Cookies["曲奇名称"].Value = "Insus.NET";

 

读Cookie语法:

if (System.Web.HttpContext.Current.Request.Cookies["曲奇名称"] != null)
        {
            string cookieValue = HttpContext.Current.Request.Cookies["曲奇名称"].Value.ToString();
        }


 

0人推荐
随时随地看视频
慕课网APP

相关阅读

添加host识别