返回上一个URL后,C#Webbrowser控件访问被拒绝

返回上一个URL后,C#Webbrowser控件访问被拒绝,c#,methods,controls,webbrowser-control,C#,Methods,Controls,Webbrowser Control,我对下面的简单代码有一个问题。我有一个循环 通过xxx.pl页上的span标记。在搜索过程中 第二个循环我必须导航到第三个循环中的另一个url(在同一服务器和同一目录上)xxx.pl/yyy,然后返回到以前的url xxx.pl。在那之后,我在 if(el.GetAttribute(“className”)==“账户区块子文本”)line 错误消息是: System.UnauthorizedAccessException HResult=0x80070005 Message=Acce

我对下面的简单代码有一个问题。我有一个循环 通过xxx.pl页上的span标记。在搜索过程中 第二个循环我必须导航到第三个循环中的另一个url(在同一服务器和同一目录上)xxx.pl/yyy,然后返回到以前的url xxx.pl。在那之后,我在

if(el.GetAttribute(“className”)==“账户区块子文本”)
line

错误消息是:

  System.UnauthorizedAccessException
  HResult=0x80070005
  Message=Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
  Source=System.Windows.Forms
有什么建议吗?在我看来,某些操作会更改el对象,因此在退出第三个循环后,我无法访问它。会话数据是否丢失?代码如下:

foreach (HtmlElement el in doc.GetElementsByTagName("span"))
   {
                          
       if (el.GetAttribute("className") == "account-block-subtext")
       {

       foreach (HtmlElement elchild in el.Children)
       {

       if (elchild.TagName == "A")
        {
       string alink = "";
       try { alink = elchild.GetAttribute("href"); } catch { alink = ""; }
       if (alink.Contains("/user/bbb.php"))
       {
       // klik alink
       elchild.InvokeMember("Click");

       webBrowser1.Navigate("xxx.pl/yyy");
          
      while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
      {
        System.Windows.Forms.Application.DoEvents();
        System.Threading.Thread.Sleep(500);
        }
        //Debug.WriteLine(webBrowser1.Url.AbsoluteUri);

        foreach (HtmlElement cashmail in doc.GetElementsByTagName("span"))
        {
         //  Debug.WriteLine(">" + cashmail.GetAttribute("className"));

      if (cashmail.GetAttribute("className") == "to_read")
      {
       Debug.WriteLine("cashmail");
       }
      }
                                //doc = doc_temp;
        }
                            
        if (alink.Contains("/shops/pppp.php"))
        {
          // klik alink
         Debug.WriteLine(alink);
         }
         alink = "";

         }
         }
         }
         }