开发者

Two-Way Communication Between HTML in .Net WebBrowser and WinForms application doesn't work on Windows Server

开发者 https://www.devze.com 2023-04-01 15:14 出处:网络
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,

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.ObjectForScriptin开发者_如何学Cg = this;
        webBrowser.ScriptErrorsSuppressed = true;
    }

    public void Foo()
    {
        //Do what needs to be done when the button is clicked
    }
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消