Hi Team,
I have a requirement in my application that i need to read a cookie from the browser which is created by the other application.
I am not able to read the cookie value.I used the below code to read all the cookies in browser. But, i couldn't get the cookie that i am looking for.
HttpCookie cookie = Request.Cookies["cookiename"];
//Check to make sure the cookie exists
if (cookie != null)
{
//Write the cookie value
String strCookieValue = cookie.Value.ToString();
//lblCookie.Text = "The cookie contains: " + strCookieValue + "";
}
please Help
Vivek KumarPosted Apr 17, 2016, 12:57 PM
Rahul ChavanPosted Apr 16, 2016, 10:11 PM
Shakti Singh DulawatPosted Apr 16, 2016, 12:38 PM
M BPosted Apr 15, 2016, 2:23 AM
Shakti Singh DulawatPosted Apr 15, 2016, 2:16 AM
[ C# ]
Response.Cookies["CookieName"].Value = "CookieValue";
// Cookies are temporally files, so you need to set how long cookie will be present on client hard disk before it is deleted
Response.Cookies["CookieName"].Expires = DateTime.Now.AddDays(100);
[ VB.NET ]
Response.Cookies("CookieName").Value = "CookieValue"
' Cookies are temporally files, so you need to set how long cookie will be present on client hard disk before it is deleted
Response.Cookies("CookieName").Expires = Now.AddDays(100)
To read cookie, you can use this code:
[ C# ]
// check if cookie exists
if(Request.Cookies["CookieName"] != null)
CookieValue = Request.Cookies["CookieName"].Value;
[ VB.NET ]
' Check if cookie exists
If Not Request.Cookies("CookieName") Is Nothing Then
CookieValue = Request.Cookies("CookieName").Value
End If