1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to start a new browser session in c# ?

Discussion in 'C, C++, C#' started by Dan2009, Feb 2, 2010.

  1. Dan2009

    Dan2009 Junior Member

    Joined:
    Jun 5, 2009
    Messages:
    133
    Likes Received:
    73
    An example: I log into yahoo mail within the webBrowser control in the program, and then load another copy of the program - I want to be able to log into multiple accounts.

    At the moment when I open up a second copy of the program, it is still logged into the first account. I need a way for the program to create a new browser session but not sure how its done.
     
  2. w84it

    w84it Regular Member

    Joined:
    Jun 18, 2009
    Messages:
    442
    Likes Received:
    752
    The IE control kinda sucks and its slow, I suggest you learn to use the WebRequest Class with Cookie containers etc if you plan on making a decent multi threaded app.

    I use the Chilkat Library for all of my apps, check some of the samle code here:
    www.example-code.com
     
    • Thanks Thanks x 1
  3. Dan2009

    Dan2009 Junior Member

    Joined:
    Jun 5, 2009
    Messages:
    133
    Likes Received:
    73
    Thanks for the advice, I guess I'll have to do some more reading :p
     
  4. smack

    smack Junior Member

    Joined:
    Feb 1, 2010
    Messages:
    182
    Likes Received:
    78
    Occupation:
    Software Engineer/Evil Genius
    Location:
    inside .NET
    in addition to WebRequest and the chillkat libraries .NET provides you with the System.Sockets namespace.

    if you're planning on doing a lot of web/internet enabled applications for a while to come it is certainly worth learning that namespace and developing your own httpclass to work with.

    once you've mastered http using the sockets namespace, the sky is the limit. :)
     
  5. jinjangjoe

    jinjangjoe Newbie

    Joined:
    Jan 14, 2009
    Messages:
    34
    Likes Received:
    6
    Location:
    New York, NY
    The WebBrowser control is still useful when you need to open web pages that execute client side script. That is not possible to do with WebRequest on its own. All you get back is the raw HTTP response and if it contains script tags you still need to find a way to process those (IF you need to). It really depends on what you are trying to do.

    Are you sure that opening 2 C# programs containing the WebBrower control shares the same session? I am pretty sure you get a new session ID. You do share the same cookies permanent (non-session) cookies that is stored in your profile. These cookies are also shared with IE. This explains why your second session automatically logs on to Yahoo Mail because it sees the cookies on disk written by the first session. However, from a purely technical perspective your second session is a new HTTP session and you are free to log on as another user without impacting the first session (just as though you were opening two browsers from the start menu vs. from Ctrl-N "new window" where you do and up with 2 browsers sharing the same session).
     
  6. smack

    smack Junior Member

    Joined:
    Feb 1, 2010
    Messages:
    182
    Likes Received:
    78
    Occupation:
    Software Engineer/Evil Genius
    Location:
    inside .NET
    client side script can be a sticky point, but bottom line the webbrowser control is not really a very good option. interacting with it is clunky and uses far more resources than it should.

    on top of that spawning multiple sessions (and using different proxies for each) isn't really possible in any particularly scalable way. so while it might save you some time in the short term, it really limits you in the long term in the ways of functionality and extensibility.

    now specifically in regards to client side script, .net does offer some pretty nifty options for interpreting and running those scripts. i don't have the bookmarks on this computer i am using now, but will see if i can dig them up a little later when i am around my laptop again.
     
  7. mline

    mline Newbie

    Joined:
    Jan 30, 2010
    Messages:
    49
    Likes Received:
    18
    Oh, there are many, many ways to deal with client side script that need not to use the WebBrowser control and at least one way that doesn't require you to make any actual requests with the WebBrowser control. I mean, after-all, if running and applying a client side script can be programmed into a WebBrowser control in the first place, you can do such a thing, programmaticly, yourself.
     
  8. ShiftySituation

    ShiftySituation Power Member

    Joined:
    Apr 15, 2010
    Messages:
    621
    Likes Received:
    314
    Occupation:
    Having fun
    Location:
    Jacksonville, FL
    A lot of times you don't need to worry about client side scripting, unless they send data back to the server. If they do, you can always just send the data yourself and problem solved. Kijiji ain't got shit on me!