0

The actual scenario is, a third party is posting data to my asp.net(ASPX) page and then redirecting the control to my page http://example.com/confirm.aspx, in the confirm.aspx page, i am able to read the data on page_load, however since the third party is doiong 2 things 1) post data and 2) redirect, at my end page_load event is getting fired twice, first time page_load has the post data and second time page_loat does notchave posted data.

I have tried to simulate the scenario at my end by mocking the same by calling http://example.com/confirm.aspx from another page example http://example.com/postdata.aspx, i am facing the same issue, the confirm.aspx page's page_load event is getting fired twice, first time page_load has the post data and second time page_loat does notchave posted data.

objHttpReq = HttpContext.Current.Request;
var inputString = String.Empty; 
objHttpReq.InputStream.Position = 0; 
using (var inputStream = new StreamReader(objHttpReq.InputStream)) 
{
inputString = inputStream.ReadToEnd(); 
}
Response.Write(inputString);

when i debug i could see the posted data in variable "inputString" but due to second time page_event load, nothing is printed on the page

your input is appreciated.

  • Hello! Does this answer your question? https://stackoverflow.com/questions/20151556/how-to-get-the-http-post-data-in-c –  Dec 18 '19 at 12:52
  • no, this does not answer my question. my point is, the client is doing 2 things 1 ) post data 2 ) redirect so, my page_load is firing twice in 1) i can read posted data and 2) nothing. so, what i need is the page_load should be only once – Being Human Dec 19 '19 at 06:41

1 Answers1

0

To answer your question, in Page_Load you can encapsulate your code like this :

if(!IsPostback)
{ }

More on IsPostBack here:

https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.page.ispostback?view=netframework-4.8

Gauravsa
  • 6,330
  • 2
  • 21
  • 30
  • no, this does not answer my question. my point is, the client is doing 2 things 1 ) post data 2 ) redirect so, my page_load is firing twice in 1) i can read posted data and 2) nothing. so, what i need is the page_load should be only once in both cases above if (!IsPostback) is true – Being Human Dec 19 '19 at 06:43