Control的C#WPF應用程序(.NET 4)可能會遇到AJAX調用差異。 這通常表現為未完成的持續的“您的請求正在處理”消息。 >
WebBrowser
根本原因:
>解決方案:通過註冊表操作的功能控制WebBrowser
>
代碼示例:
此代碼片段設置WebBrowser
註冊表密鑰以匹配檢測到的IE版本。 它還演示了基於安裝的IE版本檢索適當的仿真模式的函數。 請記住添加
的必要語句。 。
重要的考慮因素:FEATURE_BROWSER_EMULATION
using
Microsoft.Win32
System
錯誤處理:
<code class="language-csharp">private void SetBrowserFeatureControlKey(string feature, string appName, uint value) { using (var key = Registry.CurrentUser.CreateSubKey( $@"Software\Microsoft\Internet Explorer\Main\FeatureControl\{feature}", RegistryKeyPermissionCheck.ReadWriteSubTree)) { key.SetValue(appName, (uint)value, RegistryValueKind.DWord); } } private uint GetBrowserEmulationMode() { uint mode = 11000; // Default to IE11 emulation try { using (var ieKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer")) { var version = ieKey?.GetValue("svcVersion") ?? ieKey?.GetValue("Version"); if (version != null) { if (int.TryParse(version.ToString().Split('.')[0], out int browserVersion)) { switch (browserVersion) { case 7: mode = 7000; break; case 8: mode = 8000; break; case 9: mode = 9000; break; case 10: mode = 10000; break; } } } } } catch { /* Ignore registry access errors */ } return mode; } private void SetBrowserFeatureControl() { uint mode = GetBrowserEmulationMode(); SetBrowserFeatureControlKey("FEATURE_BROWSER_EMULATION", Application.ProductName, mode); } // Call SetBrowserFeatureControl() before initializing the WebBrowser control. For example: public MainWindow() { SetBrowserFeatureControl(); InitializeComponent(); }</code>
功能包括基本錯誤處理以優雅地管理潛在的註冊表訪問問題。 >
應用程序名稱:GetBrowserEmulationMode
以上是為什麼我的C#WebBrowser控件的AJAX調用與Internet Explorer不同,我該如何解決?的詳細內容。更多資訊請關注PHP中文網其他相關文章!