我正试图切换到另一个帧(没有名称或id),但出现异常。
object index = 0;
var frame = (mshtml.IHTMLWindow2)workDocument.frames.item(ref index);
frameDocument = (mshtml.IHTMLDocument2)frame.document; // Exception.
尝试了其他方式,但出现了相同的异常:
webBrowser.Document.Window.Frames[0].Document.GetElementById("userName").SetAttribute("value", username);
webBrowser.Document.Window.Frames[0].Document.GetElementById("userPassword").SetAttribute("value", password);
webBrowser.Document.Window.Frames[0].Document.GetElementById("login").InvokeMember("click");
异常:
访问被拒绝。(HRESULT中的异常:0x80070005(E_ACCESSDENIED))
我知道这是跨域的原因,我们有解决这种情况的解决方案吗
感谢
您可以捕获并忽略异常,或者调整安全设置以允许跨域脚本:
- 从WebBrowser派生类
- 创建从WebBrowser.WebBrowserSite派生的嵌套类(从嵌套类派生的唯一方法)
- 重写CreateWebBrowserSiteBase并返回Web浏览器站点的新实例
- 在Web浏览器网站上实现IServiceProvider
- 实现IServiceProvider.QueryService,使其在请求SID_SInternetHostSecurityManager服务时返回IInternetHostSecurityManager实现
- 处理IInternetHostSecurityManager.GetSecurityId,并为要使用跨域脚本的所有站点返回相同的域id。对于其他网站,请为每个域提供不同的id。注意,这会使您的应用程序面临跨域脚本攻击,因此您需要信任共享相同id的所有域
- 在表单中使用新的Web浏览器