简体   繁体   English

网页中的ActiveX不起作用(显示为损坏的图像)

[英]ActiveX in web page doesn't work (show as broken image)

I have created a very simple user control ActiveX with a simple button that show up a MessageBox. 我用一个简单的按钮创建了一个非常简单的用户控件ActiveX,该按钮显示一个MessageBox。

namespace AxCPW
{
    public partial class Test: UserControl, ITest
    {
        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Hello World");
        }
    }
}

Next I have created a web page inside my asp.net project and i have embedded my usercontrol in it. 接下来,我在asp.net项目中创建了一个网页,并将用户控件嵌入其中。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
    <object id="myControl" name="myControl" classid="AxCPW.dll#AxCPW.Test" width="100" height="100">
    </object>
</body>
</html>

The problem is i see a broken image instead my UserControl, i have already added my localhost web server Trusted Sites on IE9 but doesn't works. 问题是我看到一个残破的图像而不是我的UserControl,我已经在IE9上添加了我的本地主机Web服务器“受信任的站点”,但是不起作用。

I know ActiveX is an obsolete solution, but i need to use a third part sdk dll (to communicate with a device by USB) and i think the only available solution is this 我知道ActiveX是一种过时的解决方案,但是我需要使用第三方sdk dll(通过USB与设备进行通信),我认为唯一可用的解决方案是

ActiveX is a COM technology (essentially it's "COM-in-a-webpage"), and does not understand .NET technology. ActiveX是一种COM技术(本质上是“ COM-in-a-webpage”),并且不了解.NET技术。

To use an ActiveX control that has been developed in C#, you need to expose the interface through COM . 要使用C#开发的ActiveX控件,您需要通过COM公开接口 Also, you will need to register the DLL using RegAsm , rather than gacutil as you need the COM registration information written to the registry, rather than the assembly added to the GAC. 另外,您将需要使用RegAsm而不是gacutil来注册DLL,因为您需要将COM注册信息写入注册表,而不是将程序集添加到GAC。 Finally, the classid attribute has to be the COM GUID, not the "friendly name". 最后, classid属性必须是COM GUID,而不是“友好名称”。

If you need to deploy the ActiveX control automatically, and for sample HTML using the GUID, please check out my answer to Deploy C# ActiveX in a CAB for Internet Explorer use . 如果您需要自动部署ActiveX控件,并且需要使用GUID来获取示例HTML,请查看我对在CAB中部署C#ActiveX以供Internet Explorer使用的回答。

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

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