Home > Net >  HttpWebRequest trouble session to maintain access to web content
HttpWebRequest trouble session to maintain access to web content

Time:09-29

Existing page has already been set up in the session, such as page a.a SPX page setup a session (" aa ")="1";
B.a in SPX page using HttpWebRequest obtain c.a. SPX page content, c.a. SPX need to use the session (" aa "),
Now in the c.a. SPX page can't get the session,
B.a SPX code:
 
String page="http://10.0.0.223:105/c.aspx";
HttpWebRequest myHttpWebRequest=(HttpWebRequest) WebRequest. Create (page);

MyHttpWebRequest. Headers. The Add (" Cookie ", this. Request. Headers (" cookies "));//add on this, the following statement suggested timeout

HttpWebResponse myHttpWebResponse=(HttpWebResponse) myHttpWebRequest. The method GetResponse ();
The Stream myResponseStream=myHttpWebResponse. GetResponseStream ();
StreamReader myStreamReader=new StreamReader (myResponseStream, Encoding UTF8);
The string content=myStreamReader. ReadToEnd ();


Have tried to construct ASP.NET _SessionId cookie, is less than the session, tested HttpWebRequest requested page is a new session, which is the new sessionid,

MyHttpWebRequest. Headers. The Add (" Cookie ", this. Request. Headers (" cookies "));
This sentence is logged in before the statement when using cookies, using cookies can be normal use, to arise the problem after the session,

Ever solve the problem of friends, and give some advice, thank you

CodePudding user response:

Why use httpwebrequest simulation itself access yourself?
Of course, you can have the sessionid passed over

CodePudding user response:

During the sessionid to c.a. SPX, after writing a cookie can't link to the actual session, the session is in AcquireRequestState generated, if you want to transfer sessionid to the page, if we can set to cookies before AcquireRequestState, thus to recognize their own seesion
  • Related