3
我有一个C#WinForms应用程序,它使用WebBrowser
来显示一些UI元素(网页已嵌入)。当用户点击网页上的按钮时,我需要执行一些C#代码。我已按照this文章中描述的步骤进行了操作,并且在Windows 7上一切正常。但是,当我在Windows Server 2008上运行应用程序时,它没有响应按钮单击。 Windows Server 2003发生了同样的故事。我认为存在一些安全问题,但无法弄清楚它们是什么。.Net WebBrowser和WinForms应用程序中的HTML之间的双向通信在Windows Server上不起作用
这里是按钮的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
}
}