Simple Reading and Writing method of cookies
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)
}
}