in my pageload i have got the session[“name”]
When i use this code to save:
Stream stream = null;
request = (HttpWebRequest)WebRequest.Create(url);
response = (HttpWebResponse)request.GetResponse();
When it comes to this line:
response = (HttpWebResponse)request.GetResponse();
it again move on to the pageload and that time the session is null. how??? how to maintain the session in the same page. why it is cleared when this line encounters…
The reason that sessions don’t persist with HttpWebResponse is because by default,
HttpWebResponsewill not handle cookies for you. ASP.NET uses a cookie to identify which session belongs to a user.Thankfully, there’s a helper class called
CookieContainerthat can help you with this. Create aCookieContainerand attach it to your web request – on subsequent requests, you will need to attach the cookie container, or the cookies within it to the request again to persist session: