Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Security > HttpContext

Reply
Thread Tools

HttpContext

 
 
Martin Madreza
Guest
Posts: n/a
 
      11-06-2003
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?...me&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
 
Reply With Quote
 
 
 
 
Steve Jansen
Guest
Posts: n/a
 
      11-06-2003
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} {1}", response.StatusCode,
response.ResponseUri);

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

Console.WriteLine("HTTP {0} {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?...me&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


 
Reply With Quote
 
 
 
 
Martin Madreza
Guest
Posts: n/a
 
      11-07-2003
it works!!!

great - many thanks

MM
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dim context As HttpContext = HttpContext.Current Tony ASP .Net Web Controls 2 03-03-2004 04:51 PM
HttpContext.Current memememe ASP .Net 1 07-20-2003 06:27 AM
Unable to read httpcontext during session end Shawn ASP .Net 0 07-15-2003 04:50 PM
Questions on HttpContext w. jORDAN ASP .Net 1 07-01-2003 08:53 AM
HttpContext is Nothing in new Thread inside a control Claudio Biagioli ASP .Net 2 06-25-2003 03:57 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57