Answered System.Windows.Forms.WebBrowser

  • Tuesday, February 26, 2008 12:58 AM
     
     

    Hi,

    I have a question regarding the System.Windows.Forms.WebBrowser Class.  Is there a way I can pass a CookieCollection to this object?  For example, I've used HttpWebRequest to login to a password protected script.  Now I want to take that CookieCollection and pass it to the System.Windows.Forms.WebBrowser Class so the user can view these protected pages....

    Thanks,
    Andrew

All Replies

  • Wednesday, February 27, 2008 3:28 PM
     
     Answered

    Hey,

     

    Nevermind - I figured it out using the following:

     

    Code Snippet

    string cookie_string = "";
    foreach (Cookie cook in cookies)
    {

    cookie_string += cook.ToString() + ";";

    }

    this.webBrowser1.Document.Cookie = cookie_string;

     

     

    Thanks,
    Andrew

  • Thursday, January 08, 2009 2:46 PM
     
     Proposed Has Code
    I've got a similar situation. I use the HttpWebRequest/Response to login to a site, and get a list of links that are displayed in a C# WinForm Panel. To communicate with the web server I am required to provide a cookie and a GET session id, both I get from the HttpWebResponse.

    Once I have the links, I want to switch to the WebBrowser user control to allow the user to navigate to a URI and process that page and its links as if using IE. The Navigate method works fine, but I have to set the cookie before the connection will be accepted. Here is where I seem to be doing something wrong, as the cookie property will not allow me to set it. I new up a WebBrowser, use DocumentText to load an empty <head> and <body> to get a Document that isn't null, then I try to set the cookie (currently null) with the string I get from the CookieContiner. It will not take.

    As a test, I Navigate without the cookie, get refused, then in the document complete call back I'm able to set the cookie because it is initialized by the error response. I can set it to anything I want, and Navigate fine.

    I've looked at all the documentation and examples I can find, but have had no luck. Any suggestions on how to get the Cookie property to be set before I involve the web server?

    thanks
    Mark

     

    this.currentWebBrowser = new WebBrowser();  
    this.currentWebBrowser.DocumentText = @"<head></head><body></body>";  
    this.currentWebBrowser.Url = new Uri("about:blank");   
    this.currentWebBrowser.Document.Cookie = this.responseCookie; // from webResponse.Cookies  
    this.currentWebBrowser.Navigate( selectedURL);  
     

     

    • Edited by rkpt Thursday, January 08, 2009 2:49 PM text error
    • Proposed As Answer by JonPen Monday, March 28, 2011 1:41 PM
    • Unproposed As Answer by JonPen Monday, March 28, 2011 1:41 PM
    • Proposed As Answer by JonPen Monday, March 28, 2011 1:41 PM
    •  
  • Thursday, January 20, 2011 10:46 AM
     
     

    Hi ,

    Have you found any solution to your problem? I want to remove previous cookie of the web browser.For this I am trying to assign empty value in this .currentWebBrowser.Document.Cookie in document completed event. But the assignment does not work.

     

    thanks

    poonam

  • Wednesday, June 29, 2011 12:21 PM
     
     

    Hi ,

    Have you found any solution to your problem? I want to remove previous cookie of the web browser.For this I am trying to assign empty value in this .currentWebBrowser.Document.Cookie in document completed event. But the assignment does not work.

     

    thanks

    poonam

    Yes, I'm interested in the same questiuon

     

    thxs

  • Sunday, February 26, 2012 6:31 AM
     
     

    Hi people.

    First post around here.  ANY input greatly appreciated!  I am still using vb6 for most of my homemade projects.  What I'm trying to accomplish can't done in vb6 so it seems.  I thought I'd gather some info before jumping into this... some of you may suggest vb.net or such

    I am using httprequests to get to a site, select <some options> on a first webpage, and submit.  The httpreponse confirms I'm now at the captcha page.  Now need user input.  I'd want to 'continue' that session under the htmlbrowser-control in my app.

    The user could then solve the captcha and do his stuff.

    Just that idea of jumping from an httprequest to a browser, possible or not?

    Good night all of you