browser - How to block downloads in .NET WebBrowser control? -


I need to stop the .NET WebBrowser control from appearing any "Do you want to open or save this file? " And "Save As" dialogue Instead, I want to display a message box telling users that downloads download has been disabled for security reasons.

I started with FileDownload event WebBrowser , but it does not allow cancellation, after that, I use the interface DWebBrowserEvents2

This does not work with all downloads, although: URL: URL pointing to the url. EEE increase the event and can be canceled before the dialog appears. But for others (such as .do ), the user does not click open , save or cancel in the code.

There may be a possible solution, but it seems like a lot of effort and I also like cleaner solution ...

Is it possible to block any downloads Knows for

You can use the navigating event which allows the cancellation is.

Within this event, you can try to connect to the URL which is being navigated itself, inspect the http response header and the inappropriate content type is detected.

  System.Net.WebRequest r Equest = System.Net.WebRequest.Create (E.U.R.); // We only need the header part of the http response request. Method = "head"; System.Net.WebResponse response = Request. GetResponse (); // Only Text / HTML, Text / XML, Text / Plain is allowed ... Expand if necessary (Reaction! Content Type. Start ("Text") {E.Canel = True; MessageBox.Show ("Security is not allowed for resons ..."); }  

Obviously this is not a bulletproof solution but how can you start an idea (if you do not pay extra small roundtrip to get the HTTP response header only)

This is not ideal, because I am working with web applications where an additional request can be made that any action can be taken twice: - (

Then I will create some simple proxy servers that will inspect all the collected data and filter all the HTTP responses triggering the "save as" dialog in your web-browser control.

Just let your web-browser control go directly to the Internet, but send all http requests to your special proxy server, which will filter all unsafe responses from the web.


Comments