VanHackman 0 Newbie Poster

Hello,

I need to use the webBrowser control along with a proxy which requires authentication.

I have the following function, which works setting the proxy for the webBrowser control, but it seems like if it doesn't set the authentication data because the windows asking username/password still poping out. What is wrong? Is thre a way to set the authentication data for a webBrowser control?...

private void RefreshIESettings(string strProxy)
        {

            IntPtr hOpenHandle, hConnectHandle;

            const int INTERNET_OPTION_PROXY     = 38;
            const int INTERNET_OPEN_TYPE_PROXY  = 3;
            const int INTERNET_OPTION_PROXY_USERNAME = 43;
            const int INTERNET_OPTION_PROXY_PASSWORD = 44;
            const int INTERNET_OPEN_TYPE_PRECONFIG = 0;
            const int INTERNET_DEFAULT_HTTP_PORT = 80;
            const int INTERNET_SERVICE_HTTP = 3;

            Struct_INTERNET_PROXY_INFO struct_IPI;

            // Filling in structure
            struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY;
            struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy);
            struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local");

            // Allocating memory
            IntPtr intptrStruct = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI));

            // Converting structure to IntPtr
            Marshal.StructureToPtr(struct_IPI, intptrStruct, true);

            bool iReturn  = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, Marshal.SizeOf(struct_IPI));

            // Authentication Stuffs 

            hOpenHandle     = InternetOpen("WebMailer", INTERNET_OPEN_TYPE_PRECONFIG, null, null, 0);
            hConnectHandle  = InternetConnect(hOpenHandle, thesite.com", INTERNET_DEFAULT_HTTP_PORT, null, null, INTERNET_SERVICE_HTTP, 0, IntPtr.Zero);


            string strUsername = "User";

            InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY_USERNAME, Marshal.StringToHGlobalAuto(strUsername), strUsername.Length + 1);

            string strPassword = "Pass";
            InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY_PASSWORD, Marshal.StringToHGlobalAuto(strPassword), strPassword.Length + 1);
        }