On May 5, 11:59 am, Davej <
galt...@hotmail.com> wrote:
> On May 5, 11:08 am, Arne Vajhøj <
a...@vajhoej.dk> wrote:
> > On 5/5/2012 11:57 AM, Davej wrote:
> > > On May 5, 10:53 am, Arne Vajhøj<
a...@vajhoej.dk> wrote:
> > >> On 5/5/2012 11:34 AM, Davej wrote:
>
> > >>> I thought I had WebClient working, but it isn't working right. I
> > >>> establish a session with Session["sessname"] = myid and use
> > >>> Response.Redirect("newpage") and I keep returning the hidden
> > >>> "__VIEWSTATE" and "__EVENTVALIDATION" fields, but my session dies
> > >>> immediately.
>
> > >>> WebClient keeps returning the VS and EV but they aren't changing.
>
> > >> And you are also returning the right session cookie?
> [....]
> > >> If you control the
ASP.NET side, then you could disable
> > >> view state.
>
> > > Cookies? Does Session[] create a cookie? I am just extracting and
> > > returning the VS and EV strings. Thanks.
>
> >
ASP.NET gives you a cookie that identifies the session.
>
> > When you send that with the following requests, then you
> > get the correct Session object associated with the request.
>
> > ViewState stores the page context which is different.
>
> > Arne
>
> NameValueCollection NameValPairs = new NameValueCollection();
>
> NameValPairs.Add("form2", "");
> NameValPairs.Add("__VIEWSTATE", m_strVS);
> NameValPairs.Add("__EVENTVALIDATION", m_strEV);
> NameValPairs.Add("Input", update);
>
> m_pageBuffer = m_client.UploadValues(uriString, "POST", NameValPairs);
>
> So is there (hopefully) something simple like
> AddCookie("SessionState")
>
> ???
> I don't see it.
Oh, so if I use an instance of a CookieAwareWebClient what do I
actually have to do to make it work? Declare the address of the page
as a Uri and then call GetWebRequest before using the WebClient? This
stuff is over my head. Thanks.
public class CookieAwareWebClient : WebClient
{
private readonly CookieContainer m_container = new
CookieContainer();
protected override WebRequest GetWebRequest(Uri address)
{
WebRequest request = base.GetWebRequest(address);
HttpWebRequest webRequest = request as HttpWebRequest;
if (webRequest != null)
{
webRequest.CookieContainer = m_container;
}
return request;
}
}