.net activex 无法在框架 4.0 中工作

发布于 2024-12-23 13:24:15 字数 699 浏览 2 评论 0原文

我有 .net usercontrol 并在 asp.net 页面中将其显示为对象。 如果用户控件的 dll 的目标框架是 3.5 - 一切正常。 如果我将其更改为 .net 4.0 - activex 不可见。

用户控制非常简单。它只是一个按钮和一个标签:

[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 + "";
    }
}

这是 html 代码:

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

为什么它不起作用?

I have .net usercontrol and I show it in asp.net page as Object.
If the target framework of the usercontrol's dll is 3.5 - everything works.
If I change it to .net 4.0 - the activex doesn't visible.

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:

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

Why it's not working?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

但可醉心 2024-12-30 13:24:15

IE 中的托管控件现在默认被阻止(从 v4 或 v4.5 开始)。请参阅“Web 应用程序”下的 MSDN 文章

幸运的是,使用这些注册表项重新启用该功能非常容易:

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

x64 密钥为我修复了该问题,使用编译为 .Net v3.5 SP1 的控件在 Win7 (x64) 上运行 IE8 (x32) x32。

Hosting controls in IE is now blocked by default (as of v4 or v4.5). See MSDN article under 'Web Applications'.

Fortunately it is super-easy to re-enable the functionality with these reg keys:

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.

陌伤ぢ 2024-12-30 13:24:15

.NET 版本 4 不再支持 Windows 窗体控件,并且已删除对它们的支持。

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

*互联网中的托管控件资源管理器*
您不能再在 Internet Explorer 中托管 Windows 窗体控件,因为有更好的解决方案可以在 Web 上托管控件。因此,IEHost.dll 和 IEExec.exe 程序集已从 .NET Framework 中删除。

您可以使用以下技术在 Web 应用程序中进行自定义控件开发:

• 您可以创建 Silverlight 应用程序并将其配置为在浏览器外部运行。有关详细信息,请参阅浏览器外支持。

• 您可以构建XAML 浏览器应用程序(XBAP) 以利用WPF 功能(需要客户端计算机上的.NET Framework)。有关详细信息,请参阅 WPF XAML 浏览器应用程序概述。

Windows Forms controls are no longer supported in .NET Version 4 and support for them have been removed.

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

*Hosting controls in 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. Therefore, the IEHost.dll and IEExec.exe assemblies have been removed from the .NET Framework.

You can use the following technologies for custom control development in Web applications:

• You can create a Silverlight application and configure it to run outside the browser. 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). For more information, see WPF XAML Browser Applications Overview.

护你周全 2024-12-30 13:24:15

我一直在尝试相同的方法并发现以下内容:

您无法再在 Internet Explorer 中托管 Windows 窗体控件,因为有更好的解决方案可以在 Web 上托管控件。因此,IEHost.dll 和 IEExec.exe 程序集已从 .NET Framework 中删除。

来自这篇文章: http://msdn.microsoft.com/en-us/library /ee941656.aspx

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. Therefore, the IEHost.dll and IEExec.exe assemblies have been removed from the .NET Framework.

from this article: http://msdn.microsoft.com/en-us/library/ee941656.aspx

那片花海 2024-12-30 13:24:15

这可能是应用于已升级到 .NET 4 的程序集的安全规则集的问题。

使用早期版本的 .NET Framework 编译的程序集具有 1 级透明度。从以前的版本升级到 4.0 的程序集默认具有 2 级透明度。您可以明确地将它们设置为级别 1。

尝试将以下内容添加到 AssemblyInfo.cs

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

有关安全规则集的详细信息,请参阅:

This probably is an issue with the security ruleset being applied to assemblies that have been upgraded to .NET 4.

Assemblies that are compiled with earlier versions of the .NET Framework have level 1 transparency. Assemblies that have been upgraded to 4.0 from previous versions have level 2 transparency by default. You can explicitly make them level 1 instead.

Try adding the following to AssemblyInfo.cs:

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

For more info on the security rule sets please refer to:

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