.Net WebBrowser 和 WinForms 应用程序中的 HTML 之间的双向通信在 Windows Server 上不起作用
我有一个 C# WinForms 应用程序,它使用 WebBrowser
来显示一些 UI 元素(嵌入网页)。当用户单击网页上的按钮时,我需要执行一些 C# 代码。我已按照这篇文章中所述的步骤操作,一切正常在 Windows 7 上。但是,当我在 Windows Server 2008 上运行该应用程序时,它对按钮单击没有反应。同样的故事也发生在 Windows Server 2003 上。我相信存在一些安全问题,但无法弄清楚它们是什么。
这是按钮的 HTML:
<input type="button" value="Run Foo" class="wizard_button"
onclick="window.external.Foo()" />
这是 C# 代码:
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
[ComVisible(true)]
public partial class UI : Form
{
public UI()
{
//doing something
//...
webBrowser.ObjectForScripting = this;
webBrowser.ScriptErrorsSuppressed = true;
}
public void Foo()
{
//Do what needs to be done when the button is clicked
}
}
I have a C# WinForms app, which uses WebBrowser
to display some UI elements (webpage is embedded). I need to execute some C# code when the user clicks button on the webpage. I've followed the steps, described in this article and everything worked fine on Windows 7. However, when I ran the app on Windows Server 2008 it didn't react to button click. The same story happened on Windows Server 2003. I believe there are some security issues, but can't figure out what they are.
Here is button's HTML:
<input type="button" value="Run Foo" class="wizard_button"
onclick="window.external.Foo()" />
And here is the C# code:
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
[ComVisible(true)]
public partial class UI : Form
{
public UI()
{
//doing something
//...
webBrowser.ObjectForScripting = this;
webBrowser.ScriptErrorsSuppressed = true;
}
public void Foo()
{
//Do what needs to be done when the button is clicked
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我设法找出导致这种行为的原因。这都是关于“Internet Explorer 增强的安全配置”,需要将其关闭。为此,您需要打开“服务器管理器”,找到“安全信息”部分,单击“配置 IE ESC”链接并关闭此功能。 此处是一篇带有屏幕截图的文章。
I managed to figure out what caused this behaviour. It was all about "Internet Explorer Enhanced Security Configuration", which needed to be turned off. To do this you need to open "Server Manager", find "Security Information" section, click on "Configure IE ESC" link and turn this thing off. Here is an article with screenshots.