HttpContext

Discussion in 'ASP .Net Security' started by Martin Madreza, Nov 6, 2003.

  1. Hello,

    i searched 2days for a solution and maybe someone can help me.

    I'm programmin' a C# Assemblie and don't know which class I should use
    for a WebRequest where I can hold the connection like in the
    InternetExplorer.

    I connect to http://www.mypage.com:7070/main?name=myname&pass=mypass

    with HttpWebResponse and GetResponse or with a WebClient. Both ways
    deliver me the right page. I'm logged in!

    Now I want to get the http://www.mypage.com:7070/topframe page but I'm
    no longer logged in. How can I hold the connection? I tried with
    System.Web.HttpContext, WebClient or
    http://www.mypage.com:7070/topframe?name=myname&pass=mypass and
    searched the hole Web for information...

    Does the HttpContext work in C# programs?

    How does the IE handel this? i hope some on got an idea or know where
    i can find informations.

    MM
    Martin Madreza, Nov 6, 2003
    #1
    1. Advertising

  2. Martin Madreza

    Steve Jansen Guest

    Hi Martin,

    The response from
    http://www.mypage.com:7070/main?name=myname&pass=mypass likely includes
    some authentication token, such as an authentication cookie or a
    redirect to a URL with a querystring token.

    I would examine intializing the HttpWebClient.CookieContainer property,
    so that your client receives and maintains the state of cookies when
    communicating with the remote web app.

    Try the C# code below.

    Hope it helps,
    Steve


    using System;
    using System.IO; // Stream
    using System.Net; /* Uri, HttpWebRequest, HttpWebResponse, Uri
    WebException */

    namespace Sample
    {

    class WebExample
    {
    static int Main()
    {
    Uri loginUri = new
    Uri("http://www.mypage.com:7070/main?name=myname&pass=mypass");
    Uri contentUri = new Uri("http://www.mypage.com:7070/topframe");
    CookieContainer cookies = new CookieContainer();
    HttpWebRequest request;
    HttpWebResponse response;
    Stream responseStream;

    try
    {
    request = (HttpWebRequest)WebRequest.Create(loginUri);
    request.CookieContainer = cookies;
    response = (HttpWebResponse)request.GetResponse();
    Console.WriteLine("HTTP {0:D} {1}", response.StatusCode,
    response.ResponseUri);

    request = (HttpWebRequest)WebRequest.Create(contentUri );
    request.CookieContainer = cookies;
    response = (HttpWebResponse)request.GetResponse();
    responseStream = response.GetResponseStream();

    Console.WriteLine("HTTP {0:D} {1}", response.StatusCode,
    response.ResponseUri);

    // read responseStream
    responseStream.Close();
    }
    catch(WebException ex)
    {
    // handle exception here
    Console.WriteLine("Exception: {0}", ex.ToString());
    }

    return 0;
    }
    }

    }


    Martin Madreza wrote:
    > Hello,
    >
    > i searched 2days for a solution and maybe someone can help me.
    >
    > I'm programmin' a C# Assemblie and don't know which class I should use
    > for a WebRequest where I can hold the connection like in the
    > InternetExplorer.
    >
    > I connect to http://www.mypage.com:7070/main?name=myname&pass=mypass
    >
    > with HttpWebResponse and GetResponse or with a WebClient. Both ways
    > deliver me the right page. I'm logged in!
    >
    > Now I want to get the http://www.mypage.com:7070/topframe page but I'm
    > no longer logged in. How can I hold the connection? I tried with
    > System.Web.HttpContext, WebClient or
    > http://www.mypage.com:7070/topframe?name=myname&pass=mypass and
    > searched the hole Web for information...
    >
    > Does the HttpContext work in C# programs?
    >
    > How does the IE handel this? i hope some on got an idea or know where
    > i can find informations.
    >
    > MM
    Steve Jansen, Nov 6, 2003
    #2
    1. Advertising

  3. it works!!!

    great - many thanks

    MM
    Martin Madreza, Nov 7, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Claudio Biagioli
    Replies:
    2
    Views:
    4,543
    William F. Robertson, Jr.
    Jun 25, 2003
  2. w. jORDAN

    Questions on HttpContext

    w. jORDAN, Jun 30, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    421
    w. jORDAN
    Jul 1, 2003
  3. Shawn
    Replies:
    0
    Views:
    467
    Shawn
    Jul 15, 2003
  4. memememe

    HttpContext.Current

    memememe, Jul 18, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    343
    Natty Gur
    Jul 20, 2003
  5. Tony

    Dim context As HttpContext = HttpContext.Current

    Tony, Mar 2, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    296
    Teemu Keiski
    Mar 3, 2004
Loading...

Share This Page