Add httpcookie using c#.net

By
Advertisement


Introduction:
In my previous article I have explained about how to Remove hash tag from the current url-Javascript. In this article I am going to explain about how to add HttpCookie using  C# code.
Explanation:
To below method  is used to add HttpCookie using C# code. We need to pass the cookie name and cookie value as the input to this method.

protected void SetCookie(string cookieName, string cookieValue)
{
    HttpCookie myCookie = new HttpCookie(cookieName);
    DateTime now = DateTime.Now;
    myCookie.Value = cookieValue;
    myCookie.Expires = now.AddMinutes(20);
    Response.Cookies.Add(myCookie);
}
Below is the sample usage of the above code.
SetCookie("name", "your name");
Do you like this article? Help us to improve. If you have any queries post it in comments. We will give you the solution.

0 comments:

Post a Comment

Online Casino