Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Using HttpWebRequest when the requested page does a Response.Redirect

Reply
 
Old 12-24-2008   #1 (permalink)
APA


 
 

Using HttpWebRequest when the requested page does a Response.Redirect

I'm having a problem saving cookies when the page I am requesting is doing a Response.Redirect. I am creating a WinForm app that will request page
from a site that is of course protected by login name and password. I have no problem logging in but the login page creates several cookies and
redirects to the member home page. During this redirect process the code doesn't stop so that I can collect the cookies for later responses (because
the cookies have user info in them that identify your later requests). Is there anyway to deal with pages that do response.redirect and get the
intermin page's response before the webrequest object goes on to the new page? I'm not using an asynchronous methods right now but was wondering if
that could be a solution. I don't know if the async method would be called when the redirect is sent. Any ideas would sure be appreciated.

My System SpecsSystem Spec
Old 12-25-2008   #2 (permalink)
deostroll


 
 

Re: Using HttpWebRequest when the requested page does aResponse.Redirect

On Dec 25, 5:37*am, APA <buddy...@xxxxxx> wrote:
Quote:

> I'm having a problem saving cookies when the page I am requesting is doing a Response.Redirect. *I am creating a WinForm app that will request page
> from a site that is of course protected by login name and password. *I have no problem logging in but the login page creates several cookies and
> redirects to the member home page. *During this redirect process the code doesn't stop so that I can collect the cookies for later responses (because
> the cookies have user info in them that identify your later requests). *Is there anyway to deal with pages that do response.redirect and get the
> intermin page's response before the webrequest object goes on to the new page? *I'm not using an asynchronous methods right now but was wondering if
> that could be a solution. *I don't know if the async method would be called when the redirect is sent. *Any ideas would sure be appreciated.
Hi,

I am not sure if the WebRequest/WebResponse classes can be used for
our day-to-day "browsing" needs. Its only meant to send a request and
get a response. This is what I think. I have not previously been in a
scenario where I had to deal with cookies. Perhaps the response object
lets you to interact with the cookies somehow, I don't know. But since
you are using winforms why not try using the WebBrowser control for
your task.

--deostroll
My System SpecsSystem Spec
Old 12-26-2008   #3 (permalink)
Joris van Lier


 
 

Re: Using HttpWebRequest when the requested page does a Response.Redirect

"APA" <buddy__a@xxxxxx> wrote in message
news:unI1zjiZJHA.4480@xxxxxx
Quote:

> I'm having a problem saving cookies when the page I am requesting is doing
> a Response.Redirect. I am creating a WinForm app that will request page
> from a site that is of course protected by login name and password. I
> have no problem logging in but the login page creates several cookies and
> redirects to the member home page. During this redirect process the code
> doesn't stop so that I can collect the cookies for later responses
> (because the cookies have user info in them that identify your later
> requests). Is there anyway to deal with pages that do response.redirect
> and get the intermin page's response before the webrequest object goes on
> to the new page? I'm not using an asynchronous methods right now but was
> wondering if that could be a solution. I don't know if the async method
> would be called when the redirect is sent. Any ideas would sure be
> appreciated.
You cab use a CookieContainer to manage the cookies for your webrequest
http://msdn.microsoft.com/en-us/libr...container.aspx
http://msdn.microsoft.com/en-us/libr...container.aspx

C# Example

CookieContainer cookies = new CookieContainer();
cookies.Add(new Cookie("foo", "bar", "/", "www.tempuri.com"));
client.CookieContainer = cookies;

--
Joris van Lier

My System SpecsSystem Spec
Old 12-27-2008   #4 (permalink)
APA


 
 

Re: Using HttpWebRequest when the requested page does a Response.Redirect

Joris van Lier wrote:
Quote:

> "APA" <buddy__a@xxxxxx> wrote in message
> news:unI1zjiZJHA.4480@xxxxxx
Quote:

>> I'm having a problem saving cookies when the page I am requesting is
>> doing a Response.Redirect. I am creating a WinForm app that will
>> request page from a site that is of course protected by login name and
>> password. I have no problem logging in but the login page creates
>> several cookies and redirects to the member home page. During this
>> redirect process the code doesn't stop so that I can collect the
>> cookies for later responses (because the cookies have user info in
>> them that identify your later requests). Is there anyway to deal with
>> pages that do response.redirect and get the intermin page's response
>> before the webrequest object goes on to the new page? I'm not using
>> an asynchronous methods right now but was wondering if that could be a
>> solution. I don't know if the async method would be called when the
>> redirect is sent. Any ideas would sure be appreciated.
>
> You cab use a CookieContainer to manage the cookies for your webrequest
> http://msdn.microsoft.com/en-us/libr...container.aspx
>
> http://msdn.microsoft.com/en-us/libr...container.aspx
>
> C# Example
>
> CookieContainer cookies = new CookieContainer();
> cookies.Add(new Cookie("foo", "bar", "/", "www.tempuri.com"));
> client.CookieContainer = cookies;
>
> --
> Joris van Lier

Yeah that works fine when there is no Response.Redirect from the server. When the the server sends a response.redirect the cookies don't get stored
in the local CookieCollection. The do however get passed to the page that the redirect is pointed to.


My System SpecsSystem Spec
Old 12-27-2008   #5 (permalink)
APA


 
 

Re: Using HttpWebRequest when the requested page does a Response.Redirect

Joris van Lier wrote:
Quote:

> "APA" <buddy__a@xxxxxx> wrote in message
> news:unI1zjiZJHA.4480@xxxxxx
Quote:

>> I'm having a problem saving cookies when the page I am requesting is
>> doing a Response.Redirect. I am creating a WinForm app that will
>> request page from a site that is of course protected by login name and
>> password. I have no problem logging in but the login page creates
>> several cookies and redirects to the member home page. During this
>> redirect process the code doesn't stop so that I can collect the
>> cookies for later responses (because the cookies have user info in
>> them that identify your later requests). Is there anyway to deal with
>> pages that do response.redirect and get the intermin page's response
>> before the webrequest object goes on to the new page? I'm not using
>> an asynchronous methods right now but was wondering if that could be a
>> solution. I don't know if the async method would be called when the
>> redirect is sent. Any ideas would sure be appreciated.
>
> You cab use a CookieContainer to manage the cookies for your webrequest
> http://msdn.microsoft.com/en-us/libr...container.aspx
>
> http://msdn.microsoft.com/en-us/libr...container.aspx
>
> C# Example
>
> CookieContainer cookies = new CookieContainer();
> cookies.Add(new Cookie("foo", "bar", "/", "www.tempuri.com"));
> client.CookieContainer = cookies;
>
> --
> Joris van Lier

Yeah that works fine when there is no Response.Redirect from the server. When the the server sends a response.redirect the cookies don't get stored
in the local CookieCollection. The do however get passed to the page that the redirect is pointed to.


My System SpecsSystem Spec
Old 12-27-2008   #6 (permalink)
APA


 
 

Re: Using HttpWebRequest when the requested page does a Response.Redirect

Joris van Lier wrote:
Quote:

> "APA" <buddy__a@xxxxxx> wrote in message
> news:unI1zjiZJHA.4480@xxxxxx
Quote:

>> I'm having a problem saving cookies when the page I am requesting is
>> doing a Response.Redirect. I am creating a WinForm app that will
>> request page from a site that is of course protected by login name and
>> password. I have no problem logging in but the login page creates
>> several cookies and redirects to the member home page. During this
>> redirect process the code doesn't stop so that I can collect the
>> cookies for later responses (because the cookies have user info in
>> them that identify your later requests). Is there anyway to deal with
>> pages that do response.redirect and get the intermin page's response
>> before the webrequest object goes on to the new page? I'm not using
>> an asynchronous methods right now but was wondering if that could be a
>> solution. I don't know if the async method would be called when the
>> redirect is sent. Any ideas would sure be appreciated.
>
> You cab use a CookieContainer to manage the cookies for your webrequest
> http://msdn.microsoft.com/en-us/libr...container.aspx
>
> http://msdn.microsoft.com/en-us/libr...container.aspx
>
> C# Example
>
> CookieContainer cookies = new CookieContainer();
> cookies.Add(new Cookie("foo", "bar", "/", "www.tempuri.com"));
> client.CookieContainer = cookies;
>
> --
> Joris van Lier

Yeah that works fine when there is no Response.Redirect from the server. When the the server sends a response.redirect the cookies don't get stored
in the local CookieCollection. The do however get passed to the page that the redirect is pointed to.



My System SpecsSystem Spec
Old 12-27-2008   #7 (permalink)
Joris van Lier


 
 

Re: Using HttpWebRequest when the requested page does a Response.Redirect


"APA" <buddy__a@xxxxxx> wrote in message
news:4955C107.6080106@xxxxxx
Quote:

> Joris van Lier wrote:
Quote:

>> "APA" <buddy__a@xxxxxx> wrote in message
>> news:unI1zjiZJHA.4480@xxxxxx
Quote:

>>> I'm having a problem saving cookies when the page I am requesting is
>>> doing a Response.Redirect. I am creating a WinForm app that will
>>> request page from a site that is of course protected by login name and
>>> password. I have no problem logging in but the login page creates
>>> several cookies and redirects to the member home page. During this
>>> redirect process the code doesn't stop so that I can collect the cookies
>>> for later responses (because the cookies have user info in them that
>>> identify your later requests). Is there anyway to deal with pages that
>>> do response.redirect and get the intermin page's response before the
>>> webrequest object goes on to the new page? I'm not using an
>>> asynchronous methods right now but was wondering if that could be a
>>> solution. I don't know if the async method would be called when the
>>> redirect is sent. Any ideas would sure be appreciated.
>>
>> You cab use a CookieContainer to manage the cookies for your webrequest
>> http://msdn.microsoft.com/en-us/libr...container.aspx
>> http://msdn.microsoft.com/en-us/libr...container.aspx
>>
>> C# Example
>>
>> CookieContainer cookies = new CookieContainer();
>> cookies.Add(new Cookie("foo", "bar", "/", "www.tempuri.com"));
>> client.CookieContainer = cookies;
>>
>> --
>> Joris van Lier
>
>
> Yeah that works fine when there is no Response.Redirect from the server.
> When the the server sends a response.redirect the cookies don't get stored
> in the local CookieCollection. The do however get passed to the page that
> the redirect is pointed to.
>
>
In case you want to inspect the cookies of a redirect response you can try
to set the AllowAutoRedirect property to false
http://msdn.microsoft.com/en-us/libr...oredirect.aspx


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
HttpWebRequest with Forms Authentication PowerShell
Intercept .asp requests and redirect to corresponding .aspx page .NET General
HttpWebRequest.GetResponese() hangs .NET General
IE7 ProcID changes on Page-Redirect Vista General
HttpWebRequest won't work in PowerShell without a Proxy PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

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