2013-10-08 110 views
6

這是在Visual Studio Express的2012web瀏覽器的網站超時

我使用WebBrowser控件登錄到不同的網站,但發現一些不響應並且超時桌面C#應用程序。

我懷疑它可能是固有運行IE7的webBrowser控件,但發現這些網站在運行IE7的舊PC上運行良好,作爲本機瀏覽器。我需要設置webBrowser中是否存在某些網站,例如下面代碼中的網站來處理回覆?

下面的代碼導航到我遇到問題的網站。如果您在本機瀏覽器中輸入登錄名和密碼的任何值,它會立即響應並引發錯誤,但在webBrowser中,它位於此處等待響應並最終超時。

任何幫助將不勝感激!

米克

namespace WindowsFormsApplication11 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     private void Form1_Load(object sender, EventArgs e) 
     { 
      webBrowser1.Navigate(
       "https://www.my.telstra.com.au/myaccount/home?red=/myaccount/"); 
     } 
    } 
} 
+1

考慮實現[web瀏覽器功能控制](http://stackoverflow.com/a/18802626/1768303)以匹配IE行爲。 – Noseratio

+1

謝謝你這麼多Noseratio - 它爲這個特定的網站工作的魅力!我會繼續在其他網站上進行測試。這裏是代碼的完整工作版本。注意 - 你可以使用Windows regedit來檢查這個程序所做的註冊表設置(我不知道它們的組合是否解決了這個問題): –

回答

0

下面是完整的工作代碼:

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 
using Microsoft.Win32; 
using System.Diagnostics; 



namespace WindowsFormsApplication11 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      SetBrowserFeatureControl(); 

      InitializeComponent(); 
     } 

     private void Form1_Load(object sender, EventArgs e) 
     { 
      webBrowser1.Navigate("https://www.my.telstra.com.au/myaccount/home?red=/myaccount/"); 

     } 

     private void SetBrowserFeatureControlKey(string feature, string appName, uint value) 
     { 
      using (var key = Registry.CurrentUser.CreateSubKey(
       String.Concat(@"Software\Microsoft\Internet Explorer\Main\FeatureControl\", feature), 
       RegistryKeyPermissionCheck.ReadWriteSubTree)) 
      { 
       key.SetValue(appName, (UInt32)value, RegistryValueKind.DWord); 
      } 
     } 
     private void SetBrowserFeatureControl() 
     { 
      // 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); 

      // make the control is not running inside Visual Studio Designer 
      if (String.Compare(fileName, "devenv.exe", true) == 0 || String.Compare(fileName, "XDesProc.exe", true) == 0) 
       return; 

      SetBrowserFeatureControlKey("FEATURE_BROWSER_EMULATION", fileName, GetBrowserEmulationMode()); // Webpages containing standards-based !DOCTYPE directives are displayed in IE10 Standards mode. 
      SetBrowserFeatureControlKey("FEATURE_AJAX_CONNECTIONEVENTS", fileName, 1); 
      SetBrowserFeatureControlKey("FEATURE_ENABLE_CLIPCHILDREN_OPTIMIZATION", fileName, 1); 
      SetBrowserFeatureControlKey("FEATURE_MANAGE_SCRIPT_CIRCULAR_REFS", fileName, 1); 
      SetBrowserFeatureControlKey("FEATURE_DOMSTORAGE ", fileName, 1); 
      SetBrowserFeatureControlKey("FEATURE_GPU_RENDERING ", fileName, 1); 
      SetBrowserFeatureControlKey("FEATURE_IVIEWOBJECTDRAW_DMLT9_WITH_GDI ", fileName, 0); 
      SetBrowserFeatureControlKey("FEATURE_NINPUT_LEGACYMODE", fileName, 0); 
      SetBrowserFeatureControlKey("FEATURE_DISABLE_LEGACY_COMPRESSION", fileName, 1); 
      SetBrowserFeatureControlKey("FEATURE_LOCALMACHINE_LOCKDOWN", fileName, 0); 
      SetBrowserFeatureControlKey("FEATURE_BLOCK_LMZ_OBJECT", fileName, 0); 
      SetBrowserFeatureControlKey("FEATURE_BLOCK_LMZ_SCRIPT", fileName, 0); 
      SetBrowserFeatureControlKey("FEATURE_DISABLE_NAVIGATION_SOUNDS", fileName, 1); 
      SetBrowserFeatureControlKey("FEATURE_SCRIPTURL_MITIGATION", fileName, 1); 
      SetBrowserFeatureControlKey("FEATURE_SPELLCHECKING", fileName, 0); 
      SetBrowserFeatureControlKey("FEATURE_STATUS_BAR_THROTTLING", fileName, 1); 
      SetBrowserFeatureControlKey("FEATURE_TABBED_BROWSING", fileName, 1); 
      SetBrowserFeatureControlKey("FEATURE_VALIDATE_NAVIGATE_URL", fileName, 1); 
      SetBrowserFeatureControlKey("FEATURE_WEBOC_DOCUMENT_ZOOM", fileName, 1); 
      SetBrowserFeatureControlKey("FEATURE_WEBOC_POPUPMANAGEMENT", fileName, 0); 
      SetBrowserFeatureControlKey("FEATURE_WEBOC_MOVESIZECHILD", fileName, 1); 
      SetBrowserFeatureControlKey("FEATURE_ADDON_MANAGEMENT", fileName, 0); 
      SetBrowserFeatureControlKey("FEATURE_WEBSOCKET", fileName, 1); 
      SetBrowserFeatureControlKey("FEATURE_WINDOW_RESTRICTIONS ", fileName, 0); 
      SetBrowserFeatureControlKey("FEATURE_XMLHTTP", fileName, 1); 
     } 

     private UInt32 GetBrowserEmulationMode() 
     { 
      int browserVersion = 7; 
      using (var ieKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer", 
       RegistryKeyPermissionCheck.ReadSubTree, 
       System.Security.AccessControl.RegistryRights.QueryValues)) 
      { 
       var version = ieKey.GetValue("svcVersion"); 
       if (null == version) 
       { 
        version = ieKey.GetValue("Version"); 
        if (null == version) 
         throw new ApplicationException("Microsoft Internet Explorer is required!"); 
       } 
       int.TryParse(version.ToString().Split('.')[0], out browserVersion); 
      } 

      UInt32 mode = 10000; // Internet Explorer 10. Webpages containing standards-based !DOCTYPE directives are displayed in IE10 Standards mode. Default value for Internet Explorer 10. 
      switch (browserVersion) 
      { 
       case 7: 
        mode = 7000; // Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode. Default value for applications hosting the WebBrowser Control. 
        break; 
       case 8: 
        mode = 8000; // Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode. Default value for Internet Explorer 8 
        break; 
       case 9: 
        mode = 9000; // Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode. Default value for Internet Explorer 9. 
        break; 
       default: 
        // use IE10 mode by default 
        break; 
      } 

      return mode; 
     } 



    } 
} 
+0

您可能不需要所有這些功能。我建議先從'FEATURE_BROWSER_EMULATION'開始,通常就夠了。 – Noseratio

1

我與WenBrowserControl經常工作,真的不記得,甚至有一次,我沒有任何問題,特別是與控制的browermode。以下是一些步驟,幫助我解決很多這樣的問題:

1)強制應用程序使用InternetExplorer的設置: 首先我建議你嘗試下

HKLM\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION 

,並增加了對您的應用程序的註冊表項

HKLM\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION` 

與值9000這迫使您的應用程序中的控件使用IE9設置。 Here你可以找到將我帶到這個解決方案的問題。其描述非常詳細。

2)在Internet Explorer中的設置: 超時問題尋找我喜歡IE的某些安全功能阻塞的東西。在我看來,Internet Explorer對網站內容有相當規定。嘗試將超時網站添加到IE的Internetsettings下的安全網站中。也嘗試減少安全站點的安全/阻止功能。

請讓我知道,如果你有任何進一步的。

+0

Thankyou colosso,我想按照你的建議嘗試Internet Explorer中的設置,但是怎麼做你在web瀏覽器控件中做到這一點? –

+0

實際上沒有可能在控制本身進行設置。但該控件基於Internet Explorer。如果您在IE中更改設置,您的控件會將這些設置應用於自身。 – colosso