web浏览器网址超时

web浏览器网址超时

本文介绍了web浏览器网址超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在Visual Studio防爆preSS 2012年桌面C#应用程序。

我使用WebBrowser控件登录到不同的网站,但发现一些不响应和超时。

我怀疑这可能是WebBrowser控件本身运行IE7,但发现该网站的做工精细的老PC上运行IE7作为本地浏览器。有什么在web浏览器,我需要设置为允许一个网站,如一个在下面的code处理的反应?

在code以下浏览到一个网站,我有麻烦了。如果您在本机浏览器输入登录名和密码的任何值,它会立即响应并抛出一个错误,但在web浏览器就坐在那里等待响应,并最终将超时。

任何帮助将是很大的AP preciated!

米克

 命名空间WindowsFormsApplication11
{
    公共部分类Form1中:形态
    {
        公共Form1中()
        {
            的InitializeComponent();
        }

        私人无效Form1_Load的(对象发件人,EventArgs的)
        {
           WebBrowser1.Navigate时(
               https://www.my.telstra.com.au/myaccount/home?red=/myaccount/);
        }
    }
}
 

解决方案

下面是完整的工作code:

 使用系统;
使用System.Collections.Generic;
使用System.ComponentModel;
使用System.Data这;
使用System.Drawing中;
使用System.Linq的;
使用System.Text;
使用System.Threading.Tasks;
使用System.Windows.Forms的;
使用的Microsoft.Win32;
使用System.Diagnostics程序;



命名空间WindowsFormsApplication11
{
    公共部分类Form1中:形态
    {
        公共Form1中()
        {
            SetBrowserFeatureControl();

            的InitializeComponent();
        }

        私人无效Form1_Load的(对象发件人,EventArgs的)
        {
           WebBrowser1.Navigate时(https://www.my.telstra.com.au/myaccount/home?red=/myaccount/);

        }

        私人无效SetBrowserFeatureControlKey(字符串功能,字符串的appName,UINT值)
        {
            使用(VAR键= Registry.CurrentUser.CreateSubKey(
                String.Concat(@软件\微软\的Internet Explorer \ MAIN \ FeatureControl \功能),
                RegistryKeyPermissionCheck.ReadWriteSubTree))
            {
                key.SetValue(的appName,(UInt32的)值,RegistryValueKind.DWord);
            }
        }
        私人无效SetBrowserFeatureControl()
        {
            // http://msdn.microsoft.com/en-us/library/ee330720(v=vs.85).aspx

            // FeatureControl设置是每个进程
            变种文件名= System.IO.Path.GetFileName(Process.GetCurrentProcess()MainModule.FileName。);

            //使控件没有Visual Studio设计中运行
            如果(的String.Compare(文件名,devenv.exe的,真正的)== 0 ||的String.Compare(文件名,XDesProc.exe,真)== 0)
                返回;

            SetBrowserFeatureControlKey(FEATURE_BROWSER_EMULATION,文件名,GetBrowserEmulationMode()); //包含网页标准的!DOCTYPE指令显示在IE10标准模式。
            SetBrowserFeatureControlKey(FEATURE_AJAX_CONNECTIONEVENTS,文件名,1);
            SetBrowserFeatureControlKey(FEATURE_ENABLE_CLIPCHILDREN_OPTIMIZATION,文件名,1);
            SetBrowserFeatureControlKey(FEATURE_MANAGE_SCRIPT_CIRCULAR_REFS,文件名,1);
            SetBrowserFeatureControlKey(FEATURE_DOMSTORAG​​E,文件名,1);
            SetBrowserFeatureControlKey(FEATURE_GPU_RENDERING,文件名,1);
            SetBrowserFeatureControlKey(FEATURE_IVIEWOBJECTDRAW_DMLT9_WITH_GDI,文件名,0);
            SetBrowserFeatureControlKey(FEATURE_NINPUT_LEGACYMODE,文件名,0);
            SetBrowserFeatureControlKey(FEATURE_DISABLE_LEGACY_COM preSSION,文件名,1);
            SetBrowserFeatureControlKey(FEATURE_LOCALMACHINE_LOCKDOWN,文件名,0);
            SetBrowserFeatureControlKey(FEATURE_BLOCK_LMZ_OBJECT,文件名,0);
            SetBrowserFeatureControlKey(FEATURE_BLOCK_LMZ_SCRIPT,文件名,0);
            SetBrowserFeatureControlKey(FEATURE_DISABLE_NAVIGATION_SOUNDS,文件名,1);
            SetBrowserFeatureControlKey(FEATURE_SCRIPTURL_MITIGATION,文件名,1);
            SetBrowserFeatureControlKey(FEATURE_SPELLCHECKING,文件名,0);
            SetBrowserFeatureControlKey(FEATURE_STATUS_BAR_THROTTLING,文件名,1);
            SetBrowserFeatureControlKey(FEATURE_TABBED_BROWSING,文件名,1);
            SetBrowserFeatureControlKey(FEATURE_VALIDATE_NAVIGATE_URL,文件名,1);
            SetBrowserFeatureControlKey(FEATURE_WEBOC_DOCUMENT_ZOOM,文件名,1);
            SetBrowserFeatureControlKey(FEATURE_WEBOC_POPUPMANAGEMENT,文件名,0);
            SetBrowserFeatureControlKey(FEATURE_WEBOC_MOVESIZECHILD,文件名,1);
            SetBrowserFeatureControlKey(FEATURE_ADDON_MANAGEMENT,文件名,0);
            SetBrowserFeatureControlKey(FEATURE_WEBSOCKET,文件名,1);
            SetBrowserFeatureControlKey(FEATURE_WINDOW_RESTRICTIONS,文件名,0);
            SetBrowserFeatureControlKey(FEATURE_XMLHTTP,文件名,1);
        }

        私人UInt32的GetBrowserEmulationMode()
        {
            INT browserVersion = 7;
            使用(VAR ieKey = Registry.LocalMachine.OpenSubKey(@SOFTWARE \微软\ Internet Explorer的,
                RegistryKeyPermissionCheck.ReadSubTree,
                System.Security.AccessControl.RegistryRights.QueryValues​​))
            {
                变种版本= ieKey.GetValue(svcVersion);
                如果(空==版)
                {
                    版本= ieKey.GetValue(版本);
                    如果(空==版)
                        抛出新ApplicationException的(Microsoft Internet Explorer中是必需的!);
                }
                int.TryParse(version.ToString()分割()[0],出browserVersion'。');
            }

            UInt32的模式= 10000; //的Internet Explorer 10的网页包含基于标准!​​DOCTYPE指令显示在IE10标准模式。针对Internet Explorer 10的默认值。
            开关(browserVersion)
            {
                案例7:
                    模式= 7000; //包含网页标准的!DOCTYPE指令显示在IE7标准模式。对于承载WebBrowser控件的应用程序默认值。
                    打破;
                案例8:
                    模式= 8000; //包含网页标准的!DOCTYPE指令显示在IE8模式。 Internet Explorer 8的默认值
                    打破;
                案例9:
                    模式= 9000; //的Internet Explorer 9的网页包含基于标准!​​DOCTYPE指令显示在IE9模式。对于Internet Explorer 9的默认值。
                    打破;
                默认:
                    //使用IE10模式默认
                    打破;
            }

            返回模式;
        }



    }
}
 

This is for a Desktop C# app in Visual Studio Express 2012.

I am using a webBrowser control to logon to various websites but find some do not respond and timeout.

I suspected it may be the webBrowser control inherently running IE7 but found the websites work fine on an old PC running IE7 as a native browser. Is there something in webBrowser I need to set to allow a website such as the one in the code below to process responses?

The code below navigates to a website I am having trouble with. If you enter any values for Login and Password in a native browser, it immediately responds and throws an error , but in a webBrowser it sits there waiting for a response and eventually times-out.

Any help would be greatly appreciated!

Mick

namespace WindowsFormsApplication11
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
           webBrowser1.Navigate(
               "https://www.my.telstra.com.au/myaccount/home?red=/myaccount/");
        }
    }
}
解决方案

Here is the complete working code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Diagnostics;



namespace WindowsFormsApplication11
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            SetBrowserFeatureControl();

            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
           webBrowser1.Navigate("https://www.my.telstra.com.au/myaccount/home?red=/myaccount/");

        }

        private void SetBrowserFeatureControlKey(string feature, string appName, uint value)
        {
            using (var key = Registry.CurrentUser.CreateSubKey(
                String.Concat(@"Software\Microsoft\Internet Explorer\Main\FeatureControl\", feature),
                RegistryKeyPermissionCheck.ReadWriteSubTree))
            {
                key.SetValue(appName, (UInt32)value, RegistryValueKind.DWord);
            }
        }
        private void SetBrowserFeatureControl()
        {
            // http://msdn.microsoft.com/en-us/library/ee330720(v=vs.85).aspx

            // FeatureControl settings are per-process
            var fileName = System.IO.Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName);

            // make the control is not running inside Visual Studio Designer
            if (String.Compare(fileName, "devenv.exe", true) == 0 || String.Compare(fileName, "XDesProc.exe", true) == 0)
                return;

            SetBrowserFeatureControlKey("FEATURE_BROWSER_EMULATION", fileName, GetBrowserEmulationMode()); // Webpages containing standards-based !DOCTYPE directives are displayed in IE10 Standards mode.
            SetBrowserFeatureControlKey("FEATURE_AJAX_CONNECTIONEVENTS", fileName, 1);
            SetBrowserFeatureControlKey("FEATURE_ENABLE_CLIPCHILDREN_OPTIMIZATION", fileName, 1);
            SetBrowserFeatureControlKey("FEATURE_MANAGE_SCRIPT_CIRCULAR_REFS", fileName, 1);
            SetBrowserFeatureControlKey("FEATURE_DOMSTORAGE ", fileName, 1);
            SetBrowserFeatureControlKey("FEATURE_GPU_RENDERING ", fileName, 1);
            SetBrowserFeatureControlKey("FEATURE_IVIEWOBJECTDRAW_DMLT9_WITH_GDI  ", fileName, 0);
            SetBrowserFeatureControlKey("FEATURE_NINPUT_LEGACYMODE", fileName, 0);
            SetBrowserFeatureControlKey("FEATURE_DISABLE_LEGACY_COMPRESSION", fileName, 1);
            SetBrowserFeatureControlKey("FEATURE_LOCALMACHINE_LOCKDOWN", fileName, 0);
            SetBrowserFeatureControlKey("FEATURE_BLOCK_LMZ_OBJECT", fileName, 0);
            SetBrowserFeatureControlKey("FEATURE_BLOCK_LMZ_SCRIPT", fileName, 0);
            SetBrowserFeatureControlKey("FEATURE_DISABLE_NAVIGATION_SOUNDS", fileName, 1);
            SetBrowserFeatureControlKey("FEATURE_SCRIPTURL_MITIGATION", fileName, 1);
            SetBrowserFeatureControlKey("FEATURE_SPELLCHECKING", fileName, 0);
            SetBrowserFeatureControlKey("FEATURE_STATUS_BAR_THROTTLING", fileName, 1);
            SetBrowserFeatureControlKey("FEATURE_TABBED_BROWSING", fileName, 1);
            SetBrowserFeatureControlKey("FEATURE_VALIDATE_NAVIGATE_URL", fileName, 1);
            SetBrowserFeatureControlKey("FEATURE_WEBOC_DOCUMENT_ZOOM", fileName, 1);
            SetBrowserFeatureControlKey("FEATURE_WEBOC_POPUPMANAGEMENT", fileName, 0);
            SetBrowserFeatureControlKey("FEATURE_WEBOC_MOVESIZECHILD", fileName, 1);
            SetBrowserFeatureControlKey("FEATURE_ADDON_MANAGEMENT", fileName, 0);
            SetBrowserFeatureControlKey("FEATURE_WEBSOCKET", fileName, 1);
            SetBrowserFeatureControlKey("FEATURE_WINDOW_RESTRICTIONS ", fileName, 0);
            SetBrowserFeatureControlKey("FEATURE_XMLHTTP", fileName, 1);
        }

        private UInt32 GetBrowserEmulationMode()
        {
            int browserVersion = 7;
            using (var ieKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer",
                RegistryKeyPermissionCheck.ReadSubTree,
                System.Security.AccessControl.RegistryRights.QueryValues))
            {
                var version = ieKey.GetValue("svcVersion");
                if (null == version)
                {
                    version = ieKey.GetValue("Version");
                    if (null == version)
                        throw new ApplicationException("Microsoft Internet Explorer is required!");
                }
                int.TryParse(version.ToString().Split('.')[0], out browserVersion);
            }

            UInt32 mode = 10000; // Internet Explorer 10. Webpages containing standards-based !DOCTYPE directives are displayed in IE10 Standards mode. Default value for Internet Explorer 10.
            switch (browserVersion)
            {
                case 7:
                    mode = 7000; // Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode. Default value for applications hosting the WebBrowser Control.
                    break;
                case 8:
                    mode = 8000; // Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode. Default value for Internet Explorer 8
                    break;
                case 9:
                    mode = 9000; // Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode. Default value for Internet Explorer 9.
                    break;
                default:
                    // use IE10 mode by default
                    break;
            }

            return mode;
        }



    }
}

这篇关于web浏览器网址超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 20:46