简体   繁体   English

.net activex在Framework 4.0中不起作用

[英].net activex not working in framework 4.0

I have .net usercontrol and I show it in asp.net page as Object. 我有.net用户控件,并在asp.net页中将其显示为“对象”。 If the target framework of the usercontrol's dll is 3.5 - everything works. 如果usercontrol的dll的目标框架为3.5,则一切正常。 If I change it to .net 4.0 - the activex doesn't visible. 如果我将其更改为.net 4.0,则ActiveX不可见。

The usercontrol is very simple. 用户控件非常简单。 It's just one button and one label: 这只是一个按钮和一个标签:

[ComVisible(true)]
public partial class UserControl1 : UserControl
{
    public UserControl1()
    {
        InitializeComponent();
        label1.Text = "0";
    }
    private void button1_Click(object sender, EventArgs e)
    {
        label1.Text = Convert.ToInt32(label1.Text) + 1 + "";
    }
}

And this is the html code: 这是html代码:

<object id="myControl2" name="myControl2"
    classid="http:ClassLibrary1.dll#ClassLibrary1.UserControl1" 
    width="300" height="350" />
</asp:Content>

Why it's not working? 为什么不起作用?

Hosting controls in IE is now blocked by default (as of v4 or v4.5). 现在默认情况下(自v4或v4.5开始)阻止IE中的托管控件。 See MSDN article under 'Web Applications'. 请参阅“ Web应用程序”下的MSDN文章

Fortunately it is super-easy to re-enable the functionality with these reg keys: 幸运的是,使用以下reg键重新启用功能非常容易:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework]
"EnableIEHosting"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework]
"EnableIEHosting"=dword:00000001

The x64 key was the one that fixed it for me, running IE8 (x32) on Win7 (x64) using a .Net v3.5 SP1 control compiled for x32. x64密钥是为我修复的密钥,它使用为x32编译的.Net v3.5 SP1控件在Win7(x64)上运行IE8(x32)。

Windows Forms controls are no longer supported in .NET Version 4 and support for them have been removed. .NET版本4不再支持Windows窗体控件,并且已删除了对它们的支持。

http://msdn.microsoft.com/en-us/library/vstudio/ee941656(v=vs.100).aspx http://msdn.microsoft.com/zh-CN/library/vstudio/ee941656(v=vs.100).aspx

* Hosting controls in Internet Explorer * * Internet Explorer中的托管控件 *
You can no longer host Windows Forms controls in the Internet Explorer, because there are better solutions for hosting controls on the Web. 您不再可以在Internet Explorer中托管Windows窗体控件,因为对于在Web上托管控件有更好的解决方案。 Therefore, the IEHost.dll and IEExec.exe assemblies have been removed from the .NET Framework. 因此,已从.NET Framework中删除IEHost.dll和IEExec.exe程序集。

You can use the following technologies for custom control development in Web applications: 您可以将以下技术用于Web应用程序中的自定义控件开发:

• You can create a Silverlight application and configure it to run outside the browser. •您可以创建Silverlight应用程序并将其配置为在浏览器外部运行。 For more information, see Out-of-Browser Support. 有关更多信息,请参阅浏览器外支持。

• You can build a XAML browser application (XBAP) to take advantage of WPF capabilities (requires the .NET Framework on client machines). •您可以构建XAML浏览器应用程序(XBAP)以利用WPF功能(需要客户端计算机上的.NET Framework)。 For more information, see WPF XAML Browser Applications Overview. 有关更多信息,请参见WPF XAML浏览器应用程序概述。

This probably is an issue with the security ruleset being applied to assemblies that have been upgraded to .NET 4. 这可能是安全规则集应用于已升级到.NET 4的程序集的问题。

Assemblies that are compiled with earlier versions of the .NET Framework have level 1 transparency. 用早期版本的.NET Framework编译的程序集具有1级透明性。 Assemblies that have been upgraded to 4.0 from previous versions have level 2 transparency by default. 从以前的版本升级到4.0的程序集默认情况下具有2级透明性。 You can explicitly make them level 1 instead. 您可以将它们明确设置为1级。

Try adding the following to AssemblyInfo.cs : 尝试将以下内容添加到AssemblyInfo.cs

using System.Security;
// ...
[assembly: SecurityRules(SecurityRuleSet.Level1)]

For more info on the security rule sets please refer to: 有关安全规则集的更多信息,请参考:

I have been trying the same and found the following: 我一直在尝试相同的方法,发现以下内容:

You can no longer host Windows Forms controls in the Internet Explorer, because there are better solutions for hosting controls on the Web. 您不再可以在Internet Explorer中托管Windows窗体控件,因为对于在Web上托管控件有更好的解决方案。 Therefore, the IEHost.dll and IEExec.exe assemblies have been removed from the .NET Framework. 因此,已从.NET Framework中删除IEHost.dll和IEExec.exe程序集。

from this article: http://msdn.microsoft.com/en-us/library/ee941656.aspx 从这篇文章中获得: http : //msdn.microsoft.com/en-us/library/ee941656.aspx

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

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