Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 如何使用IE8/IE9通过远程加载的DLL(无需事先注册)部署C#ActiveX对象,然后使用javascript访问它?_.net_Internet Explorer_Activex_Activexobject - Fatal编程技术网

.net 如何使用IE8/IE9通过远程加载的DLL(无需事先注册)部署C#ActiveX对象,然后使用javascript访问它?

.net 如何使用IE8/IE9通过远程加载的DLL(无需事先注册)部署C#ActiveX对象,然后使用javascript访问它?,.net,internet-explorer,activex,activexobject,.net,Internet Explorer,Activex,Activexobject,我需要远程加载包含ActiveX对象(非可视)的.NET DLL,然后使用新的ActiveXObject()方法通过javascript访问它 当前IE8正在使用对象标记上的codebase属性的路径正确加载此DLL,但ActiveXObject失败,因为ActiveX引导程序在注册表中找不到该DLL 我使用ProcMon跟踪正在发生的事件,并可以验证DLL是否正在下载,以及新的ActiveXObject方法是否正在探测注册表。但第二部分失败,因为ActiveX对象不在注册表中 <body

我需要远程加载包含ActiveX对象(非可视)的.NET DLL,然后使用新的ActiveXObject()方法通过javascript访问它

当前IE8正在使用对象标记上的codebase属性的路径正确加载此DLL,但ActiveXObject失败,因为ActiveX引导程序在注册表中找不到该DLL

我使用ProcMon跟踪正在发生的事件,并可以验证DLL是否正在下载,以及新的ActiveXObject方法是否正在探测注册表。但第二部分失败,因为ActiveX对象不在注册表中

<body>
    <object
        name="Hello World"
        classid="clsid:E86A9038-368D-4e8f-B389-FDEF38935B2F"
        codebase="http://localhost/bin/Debug/Test.ActiveX.dll">
    </object>  

    <script type="text/javascript">    
        var hw = new ActiveXObject("Test.ActiveX.HelloWorld");
        alert(hw.greeting());
    </script>    
</body>

这个问题的简单答案是你不能;IE不会加载它不知道的activex控件

您可以做的是找到一种方法来安装DLL(从而注册ActiveX控件),然后在安装后加载它。从本质上讲,如果没有用户的任何提示,这是不可能“自动”完成的,可能是因为这将是一个噩梦般的安全漏洞

现在,如果您只是在寻找ActiveX控件的“本机”安装方法,那么您可以指定一个CAB文件。它不会“自动”为您完成所有操作,但它可以用于让IE提示用户安装ActiveX控件,这将导致安装程序运行

有关如何使用此方法的信息,请访问


用C#做你想做的事情可能不是一个非常灵活的方法;它只有在用户安装了.net的情况下才能工作,而且我从未尝试过使用CAB文件安装.net ActiveX控件。我建议您考虑使用常规浏览器插件或C++ ActiveX控件。您可以查看在C++中创建一些可以作为ActiveX控件的操作,也可以在所有其他浏览器上工作。.NETCOM注册资料只能由理解.NET的人使用(例如regasm)。不确定IE是否有这种能力。@BenLaan我也遇到了类似的问题。如果你不介意的话,你能解释一下你最后做了什么吗?还要注意,你可以把一个.msi文件放在一个.cab文件()
namespace Test
{
    [Guid("E86A9038-368D-4e8f-B389-FDEF38935B2F")]
    [InterfaceType(ComInterfaceType.InterfaceIsDual)]
    [ComVisible(true)]
    public interface IHelloWorld
    {
        [DispId(0)]
        string Greeting();
    }

    [ComVisible(true)]
    [ProgId("Test.ActiveX.HelloWorld")]
    [ClassInterface(ClassInterfaceType.None)]
    [ComDefaultInterface(typeof(IHelloWorld))]
    public class HelloWorld : IHelloWorld    
    {
        [ComRegisterFunction()]
        public static void RegisterClass(string key)
        {
            // Strip off HKEY_CLASSES_ROOT\ from the passed key as I don't need it
            StringBuilder sb = new StringBuilder(key);
            sb.Replace(@"HKEY_CLASSES_ROOT\ ", ""); // <-- extra space to preserve prettify only.. not in the real code

            // Open the CLSID\{guid} key for write access
            using (RegistryKey k = Registry.ClassesRoot.OpenSubKey(sb.ToString(), true))
            {
                // And create the 'Control' key - this allows it to show up in 
                // the ActiveX control container 
                using (RegistryKey ctrl = k.CreateSubKey("Control"))
                {
                    ctrl.Close();
                }

                // Next create the CodeBase entry - needed if not string named and GACced.
                using (RegistryKey inprocServer32 = k.OpenSubKey("InprocServer32", true))
                {
                    inprocServer32.SetValue("CodeBase", Assembly.GetExecutingAssembly().CodeBase);
                    inprocServer32.Close();
                }

                // Finally close the main key
                k.Close();
            }
        }

        ...

        public string Greeting()
        {
            return "Hello World from ActiveX";
        }
    }
}