WebBrowserControl:UnauthorizedAccessException访问框架的属性时 [英] WebBrowserControl: UnauthorizedAccessException when accessing property of a Frame

查看:241
本文介绍了WebBrowserControl:UnauthorizedAccessException访问框架的属性时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I codeD使用默认的WebBrowser控件一个非常小的网站僵尸在C#。实际上,几乎一切工作的方式,它应该工作,但我似乎有问题,我自动的最后一步。

该网站使用一些内置页框构建。这是没有太大的一个大问题,因为我只使用访问这些框架和它们的元素

<$p$p><$c$c>webBrowser1.Document.Window.Frames[0].Document.GetElementById("element").InvokeMember("click");

这可是不起作用当IFRAME的源被托管在不同的域比实际的网站。当我在网上搜索了我偶然发现了一个MSDN文章提及这一特定问题的答案,我的问题,他们指的是对跨站脚本安全的措施,这可能是此错误的原因。

我真的无法找到禁用此功能让我感动,并决定重新code一切与geckofx-12,而不是默认的(基于IE)Web浏览器控制工作的一种方式,但我跑进类似的问题...

我的问题是:有没有什么办法可以绕过这个令人讨厌的行为?我真的不关心安全问题或geckofx或默认Web浏览器控件是否正在使用,我只是想以编程方式访问正在被托管在不同的域的没有运行到UnauthorizedAccessException。

我很想从大师获得建议在那里。

解决方案

我还没有试过,但的更改文档域显然工作。

使用geckofx 12看起来这可能是由于nsIDOMHTMLDocument.SetDomainAttribute完成(该GeckoDocument.Domain没有二传手,但你可以很容易地添加)

。如果你改变了文档的子帧相匹配的域名,你可能能够访问它。

I coded a very small website bot in C# using the default WebBrowser control. Actually almost everything is working the way it is supposed to work, yet I seem to have problems with the very last step of my automation.

The website was built using several iframes. This isn't much of a big deal as I simply access those frames and their elements using

webBrowser1.Document.Window.Frames[0].Document.GetElementById("element").InvokeMember("click");

This however does not work when the source of the IFRAME is being hosted on a different domain than the actual website. As I searched the internet for an answer to my problem I stumbled across an MSDN article mentioning this specific problem and they were referring to safety measures against cross site scripting which might be the reason for this error.

I couldn't really find a way of disabling this feature so I moved on and decided to recode everything to work with geckofx-12 instead of the default (IE based) web browser control, yet I ran into similar issues...

My question is: Is there any way I can bypass this annoying behaviour? I don't really care about security concerns or on whether geckofx or the default web browser control is being used, I would just like to programmatically access the elements of a site which is being hosted on a different domain without running into an UnauthorizedAccessException.

I would love to get advice from the gurus out there.

解决方案

I havent tried this but changing the document domain apparently works.

Using geckofx 12 it looks like this might be done by nsIDOMHTMLDocument.SetDomainAttribute (The GeckoDocument.Domain doesn't have a setter but you could easily add it)

IE. if you change the domain of the document to match the sub frame you might be able to access it.

这篇关于WebBrowserControl:UnauthorizedAccessException访问框架的属性时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆