仿真时 WPF WebBrowser 控件的问题 >IE7 [英] Issue With WPF WebBrowser Control When Emulation > IE7
问题描述
我有一个 C#/WPF 应用程序,它使用一个 WebBrowser 控件,该控件将一个网站作为它的主要界面(用于信息亭).该网站可以通过 javascript 调用 C# 方法进行一些本机处理.一切正常,直到我将 'FEATURE_BROWSER_EMULATION' 设置为 IE7 以上(使用下面的代码).当我对本机方法进行 javascript 调用时不会被调用,除非我从 'http://localhost' 运行网站美好的.
I have a C#/WPF application that uses a WebBrowser control that presents a website as it's primary interface (for a kiosk). The website can call a C# method via javascript for some native processing. Everything works fine until I set the 'FEATURE_BROWSER_EMULATION' above IE7 (using the code below). When I do the javascript call to the native method does not get called unless I run the website from 'http://localhost' which works fine.
我认为这是一个安全问题.我弄乱了 IE 中的所有安全设置(包括将站点设置为受信任站点"),但我似乎无法让它正常工作.
I'm assuming this is a security issue. I've messed with all of the security settings in IE (including setting the site as a 'Trusted Site'), but I can't seem to get it working.
编码我正在使用设置仿真:
Coding I'm using the set the emulation:
private void SetBrowserCompatibilityMode()
{
// http://msdn.microsoft.com/en-us/library/ee330720(v=vs.85).aspx
// FeatureControl settings are per-process
var fileName = System.IO.Path.GetFileName( Process.GetCurrentProcess().MainModule.FileName );
if ( String.Compare( fileName, "devenv.exe", true ) == 0 ) // make sure we're not running inside Visual Studio
return;
using ( var key = Registry.CurrentUser.CreateSubKey( @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION",
RegistryKeyPermissionCheck.ReadWriteSubTree ) )
{
// Webpages containing standards-based !DOCTYPE directives are displayed in IE10 Standards mode.
UInt32 mode = 11000; // 11000 = IE11, 10000 = IE10, 9000 = IE9, 8000 = IE8, 7000 = IE7;
key.SetValue( fileName, mode, RegistryValueKind.DWord );
}
using ( var key = Registry.CurrentUser.CreateSubKey( @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ZONE_ELEVATION",
RegistryKeyPermissionCheck.ReadWriteSubTree ) )
{
// disable zone elevation prevention
UInt32 mode = 0;
key.SetValue( fileName, mode, RegistryValueKind.DWord );
}
using ( var key = Registry.CurrentUser.CreateSubKey( @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BLOCK_LMZ_SCRIPT",
RegistryKeyPermissionCheck.ReadWriteSubTree ) )
{
// enable <scripts> in local machine zone
UInt32 mode = 0;
key.SetValue( fileName, mode, RegistryValueKind.DWord );
}
using ( var key = Registry.CurrentUser.CreateSubKey( @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_NINPUT_LEGACYMODE",
RegistryKeyPermissionCheck.ReadWriteSubTree ) )
{
// disable Legacy Input Model
UInt32 mode = 0;
key.SetValue( fileName, mode, RegistryValueKind.DWord );
}
}
推荐答案
禁用FEATURE_LOCALMACHINE_LOCKDOWN
、FEATURE_BLOCK_LMZ_SCRIPT
、FEATURE_BLOCK_LMZ_OBJECT
功能.您可以从此处调整工作的 C# 代码.或者,我相信您可以使用 "Web 标记" 使您的脚本再次运行.
Disable FEATURE_LOCALMACHINE_LOCKDOWN
, FEATURE_BLOCK_LMZ_SCRIPT
, FEATURE_BLOCK_LMZ_OBJECT
features. You can adapt the working C# code from here. Alternatively, I believe you can use "Mark of Web" to make your scripts run again.
这篇关于仿真时 WPF WebBrowser 控件的问题 >IE7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!