0

I have local .aspx page to generate HTML message. But when I try to request the page using this code

 HTML = new WebClient().DownloadString("http://localhost/MySite/HTMLEmail.aspx") 

it returns the HTML without the passed data through Session. If I tried to request the page directly from the browser, it displays html page with the passed data.

so why it doesn't fill the HTML message with the data when i programmatic request the page ?

Dot Freelancer
  • 4,083
  • 3
  • 28
  • 50
  • Well, if the data is tracked in session state then what originally creates that data? If all you're doing is making a single request for one page then there's no state to be tracked, so why would there be anything in session anyway? – David Sep 22 '14 at 12:23
  • Is this qn similar to what you are looking for? http://stackoverflow.com/questions/6214936/how-to-read-the-response-from-a-web-site – mrsrizan Sep 22 '14 at 12:24
  • @David I set the session data from other pages, and when it come to send the message, I request the page. – Dot Freelancer Sep 22 '14 at 12:27
  • @dotfreelancer: How are you interacting with those "other pages"? The code in the question only shows a single request to a single page. If there's more relevant code to show, please show it. And if the problem is that your web application isn't tracking session state properly then you'd likely need to focus effort on debugging *that* application and not the application which calls it. – David Sep 22 '14 at 12:29
  • @David other pages code is not related to my question. I am trying to get the response of aspx page from the same application. – Dot Freelancer Sep 22 '14 at 12:38
  • @dotfreelancer: Then your question makes no sense. Session state is tracked across multiple page requests. So if your application isn't tracking session state then multiple page requests are, by definition, relevant. If you're just making *one* request to *one* page then there *is no session state*. – David Sep 22 '14 at 12:40
  • @David you're right.. my mistake was thinking local request will use the generated data through my requests from the browser.. – Dot Freelancer Sep 22 '14 at 12:49

2 Answers2

1

it returns the HTML without the passed data through Session

Not if that's the only request being made, it doesn't. Session is used to track data across multiple requests made by a particular client. (Effectively creating a server-side "session" for that client.) If you're only requesting one page one time then there's no session state to be tracked in the first place.

If you're making other requests (not shown in the question) and the server-side application isn't tracking session state properly then the problem may be in the server-side application, not necessarily in the client.

If you're making other requests as another client then that's a completely different session. Different clients can't access each other's session state (for fairly obvious reasons).

David
  • 208,112
  • 36
  • 198
  • 279
0

i do not know how the session state is being created or maintained. if your data uses a session variables which was created by an earlier request then you need to follow the request sequence with webclient too by using a special kind of webclient extended class. you may follow this post. How do I log into a site with WebClient?

Community
  • 1
  • 1
sm.abdullah
  • 1,777
  • 1
  • 17
  • 34