You could use Navigating
event which allows cancellation.
Inside of this event, you could try to connect to URL that's being navigated yourself, inspect http response headers and cancel navigating if inappropriate ContentType is detected.
System.Net.WebRequest request = System.Net.WebRequest.Create(e.Url);
// we need only header part of http response
request.Method = "HEAD";
System.Net.WebResponse response = request.GetResponse();
// only text/html, text/xml, text/plain are allowed... extend as required
if (!response.ContentType.StartsWith("text/"))
{
e.Cancel = true;
MessageBox.Show("Not allowed for security resons...");
}
Obviously this is not bullet-proof solution but can give you an idea how to get started (if you don't mind extra tiny roundtrip just to retrieve http response headers).
Jens Bannmann wrote:
This is not ideal, as I'm dealing with
web applications where the extra
request might trigger an action being
carried out twice :-(
Then I would create some simple proxy server that would inspect all received data and would filter out all http responses that could trigger "Save as" dialog in your web-browser control.
Simply, don't let your web-browser control directly access the internet but delegate all http requests to your special proxy server that will filter out all unsafe responses from the web.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…