Robin Sizemore
Robin Sizemore

Reputation: 11

Prevent a WebBrowser object from creating history

I have a project for a client where that will take a piece of customer information and use that to open a web browser. They're currently doing this by having a button open a the URL ("http://server.com/?customerID=XYZ") in the default browser. However, they don't like this solution, as their users have a tendency to leave this (very confidential) information on their screens for longer than necessary, and it leaves the link in the browser's history, so the user can open it again and again.

The solution was a request for an application that would open the link instead in a separate windows form with no navigation available to the user, and would automatically close after a set period of time. I have that piece working fine, but opening the link in a WebBrowser object in my form still inserts the link into IE's browser history.

I can't find any solution to making the WebBrowser object private or deleting the history that works in C#, so any help on this would be greatly appreciated.

Upvotes: 0

Views: 462

Answers (2)

Robin Sizemore
Robin Sizemore

Reputation: 11

I ended up launching an inPrivate window and opening the form in that. My form then looks for the iexplore.exe process and kills it at the end of the 30 seconds.

        System.Diagnostics.Process.Start(@"c:\program files\internet explorer\iexplore.exe","-private " + _url);

Then, when the timer is finished:

            var procs = System.Diagnostics.Process.GetProcessesByName(_name);
            foreach (var proc in procs)
            {
                proc.Kill();
            }

Upvotes: 1

Fabian
Fabian

Reputation: 2086

Here is an old post where they say that a private mode is not possible. So you probably can't deactivate the browser history.

One solution would be to close the form after the amount of time and invalidate the data such that the url can't be reopened.

You can do it with Javascript:

Set a timeout on your page that is calling a special Url (with whatever syntax)

setTimeout(function(){ 
        window.location.href = 'special_close'; 
        }, 30000);

Then you can intercept this url in the WebBrowsers Navigating event and close the form:

 private void Navigating(object sender, WebBrowserNavigatingEventArgs e)
 {
      if (e.Url.OriginalString == "special_close")
      {
            // close form that contains webbrowser
            // invalidate data here such that url can't be reloaded
      }
 }

Upvotes: 0

Related Questions