日期:2014-05-17  浏览次数:20437 次

asp.net 中cookie怎么用,
我想让一个文本框的内容在刷新后不变, 按照网上的建议我试用cookie , 如下, 但是会报一个错, System.Web.HttpResponse不包含cookie定义, 是不是缺少引用,??
Response.Cookie("username").value="aa"  
username=Request.Cookies("username").value

------解决方案--------------------
引用Imports System.Web
 Public Shared Function getCookie(ByVal name As String) As String
        Dim Cookie As HttpCookie = HttpContext.Current.Request.Cookies(name)
        If Cookie Is Nothing Then
            Return ""
        Else
            Return HttpUtility.UrlDecode(Cookie.Value)
        End If
    End Function

    Public Shared Sub setCookie(ByVal name As String, ByVal value As String)
        HttpContext.Current.Response.Cookies.Add(New System.Web.HttpCookie(name, HttpUtility.UrlEncode(value)))
    End Sub
------解决方案--------------------

        public static void SetCookie(HttpResponseBase Response,string CarValue)
        {
            string CookieName = username; //car name
            int CarCookieExpires = 30; //Expires
            Response.Cookies.Add(new HttpCookie(CookieName, CarValue));
            Response.Cookies[CookieName].Expires = DateTime.Now.AddDays(CarCookieExpires); //保存1月
        }

------解决方案--------------------
引用:
C# code?1234567        public static void SetCookie(HttpResponseBase Response,string CarValue)        {            string CookieName = username; //car name            int CarCookieExpires……


修正一下。



   public static void SetCookie()
        {
            string CookieName = username; //car name
            int CarCookieExpires = 30; //Expires
            Response.Cookies.Add(new HttpCookie(CookieName,"aa"));
            Response.Cookies[CookieName].Expires = DateTime.Now.AddDays(CarCookieExpires); //保存1月