【问题标题】:Display WebPage in C#在 C# 中显示网页
【发布时间】:2018-09-09 07:47:53
【问题描述】:
【问题讨论】:
标签:
c#
html
winforms
webbrowser-control
【解决方案1】:
默认情况下,Windows 窗体应用程序使用 IE 包装器,并且不保证使用最新的 IE 版本。阅读this article,了解 IE 包装器背后发生了什么以及 Windows 仿真密钥的作用。
我的一个旧项目中的这段代码允许以编程方式为您的可执行进程更改 IE 的默认仿真版本:
private static readonly string BrowserEmulationRegistryKeyPath =
@"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION";
/// <summary>
/// Add the process name to internet explorer emulation key
> /// i do this because the default IE wrapper dose not support the latest JS features
> /// Add process to emulation key and set a DWord value (11001) for it means we want use IE.11 as WebBrowser component
/// </summary>
public bool EmulateInternetExplorer()
{
using (
var browserEmulationKey = Registry.CurrentUser.OpenSubKey(BrowserEmulationRegistryKeyPath,
true))
{
if (browserEmulationKey == null)
Registry.CurrentUser.CreateSubKey(BrowserEmulationRegistryKeyPath);
string processName = $"{Process.GetCurrentProcess().ProcessName}.exe";
// Means emulation already added and we are ready to start
if (browserEmulationKey?.GetValue(processName) != null)
return true;
// Emulation key not exists and we must add it ( We return false because application restart to take effect of changes )
if (browserEmulationKey != null)
{
browserEmulationKey.SetValue(processName, 11001, RegistryValueKind.DWord);
browserEmulationKey.Flush();
}
return false;
}
}
如果您的网站无法在最新的 Internet Explorer 中正确显示(不兼容),您应该使用其他网络浏览器包装器,例如在您的 .Net 应用程序中嵌入 Chromium 的 cefSharp。
【解决方案2】:
您可以使用 google SDK 浏览或使用显示 html 内容裁判这个
link