Being Human
Being Human

Reputation: 1

asp.net post data and get data

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.

Upvotes: 0

Views: 408

Answers (1)

Gauravsa
Gauravsa

Reputation: 6528

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

Upvotes: 0

Related Questions