简体   繁体   中英

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.

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

if(!IsPostback)
{ }

More on IsPostBack here:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM