Clear cookies, get the value of a specified cookie, add a cookie (24 hours overdue), add a cookie

Source: Internet
Author: User

Mxs&vincene─╄ovё&0000007─╄ovёmxs&vincene

Mxs&vincene─╄ovё: Today is very cruel, tomorrow is more brutal, the day after tomorrow is very good, but most people die in the evening, only those real heroes can see the sun after the day.

Mxs&vincene─╄ovё:we ' re Here's put a dent in the universe. Otherwise Why else even is here?

Text >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>

public class Cookiehelper

{

<summary>

Clear specified Cookie

</summary>

<param name= "CookieName" >cookiename</param>

public static void ClearCookie (String cookiename)

{

HttpCookie Cookie=httpcontext.current.request.cookies[cookiename];

if (cookie!=null)

{

Cookies. Expires=datetime.now.addyears (-5);

HTTPCONTEXT.CURRENT.RESPONSE.COOKIES.ADD (cookie);

}

}

  

<summary>

Gets the specified cookie value

</summary>

<param name= "CookieName" >cookiename</param>

<return></return>

public static string Getcookievalue (String cookiename)

{

HttpCookie Cookie=httpcontext.current.request.cookies[cookiename];

String Str=string.empty;

if (cookie!=null)

{

Str=cookie. Value;

}

return str;

}

  

<summary>

Add a cookie (24 hours overdue)

</summary>

<param name= "CookieName" >cookiename</param>

<param name= "Cookievalue" >cookievalue</param>

public static void Setcookie (String cookiename,string cookievalue)

{

Setcookie (Cookiename,cookievalue,datetime.now.adddays (1.0));

}

  

<summary>

Add a cookie

</summary>

<param name= "CookieName" >cookiename</param>

<param name= "Cookievalue" >cookievalue</param>

<param name= "Expires" > Expiry time </param>

public static void Setcookie (String cookiename,string cookievalue,datetime wxpiress)

{

HttpCookie Cookie =new HttpCookie (cookiename)

{

Value=cookievalue,

Expires=expires

};

HTTPCONTEXT.CURRENT.RESPONSE.COOKIE.ADD (Cookie);

}

}

Clear cookies, get the value of a specified cookie, add a cookie (24 hours overdue), add a cookie

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.