PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → Controlling cookies in an HTML display control
Controlling cookies in an HTML display control
Débuté par Simon Phillips, 02 déc. 2025 18:33 - 1 réponse
Posté le 02 décembre 2025 - 18:33
Does anyone know of a way to control cookies when displaying websites in an HTML display control?

My app is for the elderly and first time computer users and one of the feature is having the Bing search in then html display. The problem is that everything it is loaded, the Cookie choice popup window appears, regardless of if the Accept button was previously selected.

If is not just Bing but all websites such as ebay etc.

Thanks
Simon
Membre enregistré
2 messages
Posté le 10 janvier 2026 - 05:00
Because it’s not persisting the cookies (or the "Local Storage") from the previous session, the website thinks every visit is from a brand-new user and triggers the consent banner accordingly.

The solution depends on which specific control you are using, but here is a breakdown of how to fix this for the most common frameworks:

1. WebView2 (Recommended for Windows/C#)
If you are using the modern WebView2 (based on Edge/Chromium), you need to define a User Data Folder. By default, WebView2 may use a temporary folder that clears on exit.

The Fix: Set the UserDataFolder property when initializing the environment. This tells the browser exactly where to save cookies and settings so they are remembered the next time the app opens.

Code logic: var env = await CoreWebView2Environment.CreateAsync(userDataFolder: "C:\YourAppPath\UserCache"); await webView.EnsureCoreWebView2Async(env);

2. Electron or CEFSharp (Chromium-based)
If you are building a desktop app https://happyrewards.io/ with Electron or CEF (Chromium Embedded Framework), you must specify a cache path.

Electron: Ensure you aren't using an "incognito" partition. By default, Electron saves data to the user’s AppData folder.

CEFSharp: You must set CefSettings.CachePath to a valid folder on the hard drive during the initialization of the application. If this is left blank, CEF runs in "in-memory" mode, and all cookies vanish when the control is destroyed.

3. The Legacy WebBrowser Control (IE11)
If your app is using the old System.Windows.Forms.WebBrowser control, it actually shares cookies with the global Internet Explorer/Internet Options on the machine.

The Issue: If the computer has "Delete browsing history on exit" enabled in Windows Internet Options, your app will lose its cookies too.

The Fix: You may need to use P/Invoke to call InternetSetOption to force cookie persistence, but honestly, for an app aimed at the elderly, I highly recommend switching to WebView2 for a much smoother experience.