In my previous post I shows how to create cookie in javascript, now i am going to tell you how to retrieve value from a cookie in Silverlight. The code i'm using here is C# because i love this :)
I create a methode which returns the value from a cookie
string IPAddress = GetCookieValueByKey("clientIPAdd");
This is the methode
private string GetCookieValueByKey(string keyName)
{
string[] cookies = HtmlPage.Document.Cookies.Split(';');
foreach (string cookie in cookies)
{
string[] keyValue = cookie.Split('=');
if (keyValue.Length == 2)
{
if (keyValue[0].ToString() == key)
return keyValue[1];
}
}
return string.empty;
}
Hope this helps :)
I create a methode which returns the value from a cookie
string IPAddress = GetCookieValueByKey("clientIPAdd");
This is the methode
private string GetCookieValueByKey(string keyName)
{
string[] cookies = HtmlPage.Document.Cookies.Split(';');
foreach (string cookie in cookies)
{
string[] keyValue = cookie.Split('=');
if (keyValue.Length == 2)
{
if (keyValue[0].ToString() == key)
return keyValue[1];
}
}
return string.empty;
}
Hope this helps :)
No comments:
Post a Comment