Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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 me in reading the cookie value through .NET application.


What I have tried:

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 + "";
}

also try something like this :-

if (Request.Cookies["CookieName"] != null)
CookieValue = Request.Cookies["CookieName"].Value;
Posted
Updated 14-Apr-16 22:20pm
v3

You can't read a cookie which is in other domain.
Cross domain cookie read/write not possible.
 
Share this answer
 
Comments
.net developer123456789 15-Apr-16 4:15am    
Thanks,how can test in my localhost any idea ?
F-ES Sitecore 15-Apr-16 4:33am    
You need to create the cookie via localhost to read it via localhost.
Asmita Bhurke 15-Apr-16 4:38am    
In that case it won't be another application.
Can't test on localhost.
You need to publish both sites against one domain.

subdomain.domain or domain\subdirectory will work.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900