Good Evening All
i have another Question. i have created a Function that creates a Cookie with a Domain like this
private static void SetCookieExtedend(String key, String value, String path)
{
DateTime expires = DateTime.UtcNow + TimeSpan.FromDays(2000);
bool secure = false;
String domain = "Ecash";
StringBuilder cookie = new StringBuilder();
cookie.Append(String.Concat(key, "=", value));
if (expires != null)
{
cookie.Append(String.Concat(";expires=", expires.ToString("R")));
}
if (!String.IsNullOrEmpty(path))
{
cookie.Append(String.Concat(";path=", path));
}
if (!String.IsNullOrEmpty(domain))
{
cookie.Append(String.Concat(";domain=", domain));
}
if (secure)
{
cookie.Append(";secure");
}
HtmlPage.Document.SetProperty("cookie", cookie.ToString());
}
and its working well , i have set the Cookie and it was stored as this
UserID=142;expires=Mon, 14 Nov 2016 16:58:19 GMT;domain=Ecash
now i want to retrieve the Value of the Cookie and i have a function that does it like this
public static string GetCookie(string key)
{
string[] cookies = HtmlPage.Document.Cookies.Split(';');
key += '=';
foreach (string cookie in cookies)
{
string cookieStr = cookie.Trim();
if (cookieStr.StartsWith(key, StringComparison.OrdinalIgnoreCase))
{
string[] vals = cookieStr.Split('=');
if (vals.Length >= 2)
{
return vals[1];
}
return string.Empty;
}
}
return null;
}
the Following Line comes back with an empty String
string[] cookies = HtmlPage.Document.Cookies.Split(';');
Why ?
Thanks