Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 访问帧名称会在“;“访问被拒绝”;例外_C#_.net_Browser_Mshtml - Fatal编程技术网

C# 访问帧名称会在“;“访问被拒绝”;例外

C# 访问帧名称会在“;“访问被拒绝”;例外,c#,.net,browser,mshtml,C#,.net,Browser,Mshtml,我正在为IE制作一个C#工具栏,我需要访问网站中的某个框架。在我的初始测试中,我只是尝试在帧之间循环,并弹出一个带有帧名称的MessageBox。但每当我尝试这样做时,我都会遇到一个例外,说“访问被拒绝”。例外情况全文如下: 访问被拒绝。(HRESULT异常:0x80070005(E_访问被拒绝)) 代码如下: IHTMLSelectionObject currentSelection = myHTMLDocument.selection; IHTMLFramesCollection2 fra

我正在为IE制作一个C#工具栏,我需要访问网站中的某个框架。在我的初始测试中,我只是尝试在帧之间循环,并弹出一个带有帧名称的MessageBox。但每当我尝试这样做时,我都会遇到一个例外,说“访问被拒绝”。例外情况全文如下:

访问被拒绝。(HRESULT异常:0x80070005(E_访问被拒绝))

代码如下:

IHTMLSelectionObject currentSelection = myHTMLDocument.selection;

IHTMLFramesCollection2 frames = (IHTMLFramesCollection2)myHTMLDocument.frames;

for (int i = 0; i < frames.length; i++)
{
    object refIndex = i;

    IHTMLWindow2 currentFrame = (IHTMLWindow2)frames.item(ref refIndex);

    if (currentFrame != null)
    {
        MessageBox.Show(currentFrame.name);
    }
    else
        MessageBox.Show("Null");

}
IHTMLSelectionObject currentSelection=myHTMLDocument.selection;
IHTMLFramesCollection2 frames=(IHTMLFramesCollection2)myHTMLDocument.frames;
对于(int i=0;i
从我在网上的搜索中,我发现这实际上不是一个bug。人们期望它会这样做。我的问题是:做我想做的事情的正确方法是什么


提前谢谢

您收到此消息可能是因为您试图从另一个域访问帧。这条路会阻止你这样做。要使其工作,请使用IServiceProvider

IServiceProvider isp = (IServiceProvider) currentFrame;
然后使用
QueryService
进行查询,以获取IWebBrowser2对象

确保您使用了
System.Runtime.InteropServices

我已经看到了这一点:,但我不知道C#中是否有更完整的示例。