.Net WebBrowser 和 WinForms 应用程序中的 HTML 之间的双向通信在 Windows Server 上不起作用

发布于 2024-12-02 11:07:40 字数 897 浏览 0 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绝情姑娘 2024-12-09 11:07:40

我设法找出导致这种行为的原因。这都是关于“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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文