Read cookies value using C#.net Asp.Net

By
Advertisement

Introduction:
In my previous article I have explained about Delete browser cookie using C#.Net,Asp.Net. In this article I am going to explain about how to delete the browser cookies using C#.Net code.
 
Explanation:
Read a string from the Cookies collection using the cookie's name as the key.
The following example reads the value of cookie named “name”  from the browser  cookies.

Below is the method  used to read the cookie.
private string GetCookie(string cookieName)
{
    string str = "";
    HttpCookie getcook = new HttpCookie(cookieName);
    getcook = Request.Cookies[cookieName];
    str = getcook.Value.ToString();
    return str;
}
Sample usage of the method is given below.
GetCookie("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