Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I determine if a request is the result of a postback?

Tags:

asp.net

Update

I'm implementing a custom page caching solution and I don't want the request to be cached or retrieved from the cache if it's in response to a form submission or some sort of asp.net postback.

I'm trying to figure out if the current HttpRequest is a postback. Is there a way of doing this outside the context of a page or other usercontrol? In otherwords if I'm inside an HttpModule I don't have access to this.IsPostBack but I still need to determine if it is in fact a postback.

Also, are postbacks always "Post" requests or is that determined by containing form?

thanks!

like image 973
Micah Avatar asked Aug 05 '10 17:08

Micah


People also ask

What can be used to identify postback?

Which property is used to identify the Page is Post Back in ASP.NET? Page. IsPostBack property is use to check wheather page is post back.It return bool value.

Which property is set to test whether postback is occurred or not?

IsPostBack property will be set to true when the page is executing after a postback, and false otherwise. We can check the value of this property based on the value and we can populate the controls on the page.

What IsPostBack explain with example?

PostBack is the name given to the process of submitting an ASP.NET page to the server for processing. PostBack is done if certain credentials of the page are to be checked against some sources (such as verification of username and password using database).

What are postback events?

A Postback Event is a string of information that is sent to a network's specific URL that contains information about the post-install event pertinent to the network.


1 Answers

Check the Method property of the HttpWebRequest. Postbacks should be marked as POST in the Method.

Also, the way you did it in old-school asp was to check for expected post-back parameters in the body of the HTTP message (Request.Form). You could check the content of the request for data that looks like postback parameter. I'm not sure what object exactly you're working with, but if it's an HttpWebRequest, you might check the request stream from the GetResponseStream() method of the object.

like image 52
Ben McCormack Avatar answered Nov 26 '22 15:11

Ben McCormack