简体   繁体   English

对WebBrowser控件使用自定义设置

[英]Using custom settings for WebBrowser Control

I'm trying to build an c# application that uses the WebBrowser Control for, obviouly, webbrowsing. 我正在尝试构建一个使用WebBrowser控件进行Web浏览的c#应用程序。 To enhance the security of the system, i'd like to set my own security settings. 为了增强系统的安全性,我想设置自己的安全性设置。 These are two of the settings i would like to set through the software: 这是我要通过软件设置的两个设置:

  1. Disable Download for certain file-extensions (*.exe) 禁用某些文件扩展名(* .exe)的下载
  2. Disable Cookies 禁用cookie

I found, that the WebBrowser Class directly uses the settings from Internet Explorer. 我发现WebBrowser类直接使用Internet Explorer中的设置。 Is there any way to use own settings for a specific WebBrower or overide these settings (maybe just temporarely)? 有没有办法为特定的WebBrower使用自己的设置或覆盖这些设置(可能只是暂时地)?

I think the Question may be similar to this: 我认为问题可能与此类似:
Overriding IE settings when embedding a WebBrowser control using IE9 使用IE9嵌入WebBrowser控件时覆盖IE设置
(But i'm not sure... :) (但我不确定... :)

EDIT: If I change the Cookie-Settings for Internet Explorer, they will be used for my WebBrowser-Control, right? 编辑:如果我更改Internet Explorer的Cookie设置,它们将用于我的WebBrowser-Control,对吗? Is it possible to change these global Settings via C#? 是否可以通过C#更改这些全局设置? Maybe this could be an easy solution for the Problem... 也许这可能是解决问题的简单方法...

Unfortunately, it doesn't look like you can disable cookies, though you can clear them; 不幸的是,尽管您可以清除cookie,但是看起来好像不能禁用cookie。 however, when you do so, you will be clearing cookies for all IE instances on that PC (for that particular account). 但是,这样做时,将清除该PC上所有 IE实例的cookie(针对该特定帐户)。 Here is a StackOverflow with more detail . 这是更多细节的StackOverflow

As far as controlling which files may be downloaded, you probably need to use some form of the FileIOPermission Class. 至于控制哪些文件可以下载,您可能需要使用某种形式的FileIOPermission类。 Here is a StackOverflow expanding on that with an example in the answer . 这是StackOverflow的扩展,其中包含示例

Last, explore the MSDN documentation for the Webbrowser control class, and you might get closer to what you need. 最后,浏览Webbrowser控件类的MSDN文档 ,您可能会更接近所需的内容。

Good Luck! 祝好运!

You can adjust which files that can be downloaded by using the Navigating event of a webbrowser... 您可以使用网络浏览器的导航事件来调整可以下载的文件...

For Example, in the "Navigating" event for your web browser control... 例如,在您的Web浏览器控件的“导航”事件中...

if (e.Url.ToString().EndsWith(".exe"))
{
    e.Cancel = true;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM