Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Simple Reading and Writing method of cookies

Shulou Source: shulou.com Published: 2022-06-03 06:15:34 09月24日 Update

I. Writing of cookie

/ / define COOKIES, instantiate the HttpCookie class and add values

HttpCookie cookie = new HttpCookie (key, value)

/ / set the save time

Cookie.Expires = DateTime.Now.AddDays (1)

/ / add the currently instantiated cookie

Response.Cookies.Add (cookie)

II. Reading of cookie

Public static string GetOwner ()

{

If (HttpContext.Current.Request.Cookies [key] = = null)

{

Throw new Exception ("you are not logged in to the system or the session has expired, please log in again")

}

Else

{

/ / get user data

HttpCookie cook = HttpContext.Current.Request.Cookies [key]

Return HttpUtility.UrlDecode (cook.Value)

}

}

Tags: Instance login data time user system method Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Xiaomi Shulou Technology MariaDB Linux