WebBrowser Control Mishandling Cookies when Internet Explorer is Open

不羁岁月 提交于 2020-01-14 03:59:13

问题


I'm building an application in C# that makes use of the WebBrowser control. This is loading a specific page (that I did not create) that uses a popup and a cookie that determines what the last "ID" searched for was. This all works fine, except when Internet Explorer is open in the background. When Internet Explorer is open in the background, the popup only goes to the first ID ever set. It would appear that the cookies aren't being stored properly when IE is open.

Breakdown:

  • User opens Internet Explorer.
  • User opens My Application.
  • User searches for XXX on page.
  • User clicks popup. Popup displays the correct information.
  • User searches for XXY on parent page.
  • User clicks popup. Popup displays previous information (not correct).

As I said, this works fine when Internet Explorer is not open.

Does anyone know what might cause this or how to prevent it? Perhaps Internet Explorer is "locking" its cookies?


回答1:


As I often do, I discovered the problem while writing the question. This happened to be a caching issue specific to the WebBrowser Control when IE8 is installed.

This thread suggests clearing the cache of the URL before navigating. Using the following code:

using System.Runtime.InteropServices;
...
[DllImport("wininet.dll", SetLastError = true)]
private static extern long DeleteUrlCacheEntry(string lpszUrlName);

Then you can use

DeleteURLCacheEntry(pdfURL);
webBrowser.Navigate(pdfURL);


来源:https://stackoverflow.com/questions/16700981/webbrowser-control-mishandling-cookies-when-internet-explorer-is-open

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!