Windows Phone as of today doesn’t provide a property or direct API call which will help you identify whether the user has chosen to accept cookies or not. However, we can identify this pretty neatly by trying to get the cookie collection.
So to achieve this, we are going to get the cookie collection for a site which uses cookies and if it returns empty, then the user has turned off the cookies and if it has a count, then the user has preferred to use the cookies. So the below piece of code will help you.
private WebBrowser browser = new WebBrowser(); private void SetBrowserSetting() { this.browser.Source = new Uri("http://m.bing.com", UriKind.Absolute); this.browser.LoadCompleted += new System.Windows.Navigation.LoadCompletedEventHandler(Browser_LoadCompleted); } void Browser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e) { this.IsCookiesSupported = this.browser.GetCookies().Count > 0; } public bool? IsCookiesSupported { get; set; }
You can browse your favorite site in the source to find the cookie support but, do remember the below points before choosing the site.
- Site is reliable so that you don’t end up browsing a site which is down by itself.
- The page you are downloading must be as tiny as possible.
- The page should use at least one cookie.
How To Check If Cookies Are Enabled In Windows Phone