使用c#.net,ASP.NET读取浏览器cookie [英] Read browser cookie using c#.net, ASP.NET
问题描述
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.
我尝试过:
HttpCookie cookie = Request.Cookies [cookiename];
//检查以确保cookie存在
if(cookie!= null)
{
//写下cookie值
String strCookieValue = cookie.Value.ToString();
//lblCookie.Text =cookie包含:+ strCookieValue +;
}
也尝试这样的事情: -
if(Request.Cookies [CookieName ]!= null)
CookieValue = Request.Cookies [CookieName]。值;
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;
推荐答案
你无法读取cookie这是在其他领域。
跨域cookie读/写不可能。
You can't read a cookie which is in other domain.
Cross domain cookie read/write not possible.
无法在localhost上测试。
您需要针对一个域发布这两个网站。
subdomain.domain或domain \subdirectory将起作用。
Can't test on localhost.
You need to publish both sites against one domain.
subdomain.domain or domain\subdirectory will work.
这篇关于使用c#.net,ASP.NET读取浏览器cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!