Note that there are some explanatory texts on larger screens.

plurals
  1. POImplement custom 401 handling for a WebBrowser control
    primarykey
    data
    text
    <p>As per <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.createsink.aspx" rel="nofollow">this article</a>, I've extended the <code>System.Windows.Forms.WebBrowser</code> class to implement custom error-handling. Mostly, it works.</p> <p>The problem comes when the browser gets a "401 Unauthorized" response. That kind of response causes the <code>WebBrowser</code> control to display the standard Username / Password dialog. The <code>NavigateError</code> event isn't fired until that dialog is cancelled.</p> <p>So what can I do to capture the 401 response and handle it in my own custom way? </p> <p>I assumed there would be something I could do, such as that which I do to capture the <code>NavigateError</code> event, and handle those my own way but I haven't seen anything.</p> <p><strong>Edit: Solution Found!</strong><br> The important steps are:<br> 1. The WebBrowser control must <em>first</em> be navigated to a non-secure page ("about:blank" is the typical URL used) in order to avoid <a href="http://support.microsoft.com/kb/320153" rel="nofollow">KB 320153</a><br> 2. The host for the WebBrowser control must implement <code>IOleClientSite</code>, <code>IServiceProvider</code>, and <code>IAuthenticate</code>.<br> 3. <code>IServiceProvider.QueryService</code> must handle the <code>IAuthenticate</code> service request with the <code>IAuthenticate</code> implementation, all other service requests can be handled with the <code>INET_E_DEFAULT_ACTION</code> response.<br> 4. <code>IAuthenticate.Authenticate</code> is your custom authentication handler.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload