簡體   English   中英

使用SHDocVw Navigate2進行導航時,WIN10中的操作異常終止,即

[英]Operation aborted Exception in WIN10 when using SHDocVw Navigate2 for navigatng ie

我有一個C#項目,可以使用Interop.SHDocVw在IE瀏覽器中打開URL。

該代碼使用InternetExplorerClass對象的單個實例,並導航到不同的URL。 這些URL都在Intranet區域中。

該代碼在WIN7上工作正常,但在WIN10上存在問題。 IE瀏覽器在第一次中正確打開了該URL,但是當我嘗試在第二次中使用Navigation或Navigation2方法使用該URL時,出現以下錯誤:

System.Runtime.InteropServices.COMException(0x80004004):操作在SHDocVw.InternetExplorerClass.Navigate(字符串URL,對象和標志,Object&TargetFrameName,Object&PostData,Object&Headers)中中止(來自HRESULT的異常:0x80004004(E_ABORT))

我試圖以“管理員”身份運行主機應用程序,然后運行良好。 同樣,當我在IE窗口中手動導航到Internet區域中的URL時,也沒有問題,但是當手動導航至其他Intranet URL並嘗試第二次運行代碼時,該錯誤再次引發。

代碼

公共靜態無效IEOpenOnURL(string url){object o = null; bool newBrowser = false;

        //check if window is already opened 
        if(webBrowser==null)
        {
            newBrowser = true;
        }
        else
        {               
            try 
            {
                //Cannot navigate in browser with an open modal dialog
                if(webBrowser.Busy)
                {
                    MessageBox.Show("הדפדפן תפוס - סגור את החלונות הקופצים מתוך הדפדפן הפתוח");
                    return;
                }
            }
            //an error is thrown when the browser was closed by user
            catch(Exception)
            {
                newBrowser = true;
            }
        } 

        if(newBrowser)
        { 
            //create new instance of the browser
            InternetExplorer explorer = new InternetExplorerClass(); 
            webBrowser = (IWebBrowser2)explorer;  
        } 


        webBrowser.Visible = true; 
        //webBrowser.Navigate(url, ref o, ref o, ref o, ref o);
        webBrowser.Navigate2(url, ref o, ref o, ref o, ref o);

        //Set focus 
        SetForegroundWindow((IntPtr)webBrowser.HWND);
        //If browser is minimized - show it
        ShowWindow((IntPtr)webBrowser.HWND,9);
    } 
}

我不會說我知道確切的答案。 但是我會說您通常應該通過接口而不是通過類來初始化Internet Explorer。 嘗試直接初始化類時遇到錯誤。

嘗試這個 :

  SHDocVw.InternetExplorer IE = new SHDocVw.InternetExplorer();
  IE.Visible = true;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM