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




"APA" <buddy__a@xxxxxxxxxxx> wrote in message news:4955C107.6080106@xxxxxxxxxxxxxx
Joris van Lier wrote:
"APA" <buddy__a@xxxxxxxxxxx> wrote in message news:unI1zjiZJHA.4480@xxxxxxxxxxxxxxxxxxxxxxx
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/library/system.net.httpwebrequest.cookiecontainer.aspx http://msdn.microsoft.com/en-us/library/system.net.cookiecontainer.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/library/system.net.httpwebrequest.allowautoredirect.aspx


.



Relevant Pages

  • Re: WebRequest and ASP username/password form authentication
    ... POST method. ... sure about cookies. ... > login page and check its HTML source. ... This is the request data you want to send to login. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Login ctrl - cookies not accepted?
    ... authentication and SQL membership provider, OS is Vista 64, browser IE ... When I use URI for cookies everything works fine. ... If I use cookieless=UseCookies, after hitting Login button, user is ... as an unspecified page hit (no redirect ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Login ctrl - cookies not accepted?
    ... It caused that authentification cookies were not sent to web site. ... The firts default page is accessible without authetication, so the login ... authentication and SQL membership provider, OS is Vista 64, browser IE ... as an unspecified page hit (no redirect ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Using HttpWebRequest when the requested page does 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. ... During this redirect process the code doesn't stop so that I can collect the cookies for later responses. ...
    (microsoft.public.dotnet.general)
  • Re: WebRequest and ASP username/password form authentication
    ... > I want to use WebRequest to get the contents of a web page. ... You have to supply user name and password with a POST request yourself. ... login page and check its HTML source. ... assume the web app is using cookies. ...
    (microsoft.public.dotnet.languages.csharp)

Quantcast