Search code examples
javascriptasp.netdopostback

How does __doPostback creates a url on asp.net website?


Please take a look at the below URL - https://www.event-reg.biz/oem-Koelnmesse/OnlineExhListing

In the sort by dropdown, you can select "Exhibitor A to Z" and press search. After when the data appears, they have a javascript function for each link (javascript:__doPostBack('ctl00$MainContent$grdExhList$ctl00$ctl04$lnkExhLink','')) that executes in the browser to create a unique URL.

For example https://www.event-reg.biz/oem-Koelnmesse/OnlineExh?e=/v5urzZW/hm8SuWqRTOYlg==&p=https%3a%2f%2fwww.event-reg.biz%2foem-Koelnmesse%2fOnlineExhListing this URL gets created for the above Javascript function call.

I have done research about __doPostBack function but that doesn't seem to help. Any kind of help or suggestion is appreciated.

Thank you in advance.


Solution

  • Sequence of events:

    1. Link is clicked on the client side. It will invoke the __doPostBack method which will invoke a POST to the URL: "https://www.event-reg.biz/oem-Koelnmesse/OnlineExhListing" and passes the __EVENTTARGET with value: "ctl00$MainContent$grdExhList$ctl00$ctl04$lnkExhLink", one among the many key/values posted.
      On receiving the request at the server side, server provides the below response back to the client: "1|#||4|157|pageRedirect||%2foem-Koelnmesse%2fOnlineExh.aspx%3fe%3d%2fv5urzZW%2fhm8SuWqRTOYlg%3d%3d%26p%3dhttps%253a%252f%252fwww.event-reg.biz%252foem-Koelnmesse%252fOnlineExhListing|"
    2. Client now invokes a GET request to the URL received in the previous POST response which is: "%2foem-Koelnmesse%2fOnlineExh.aspx%3fe%3d%2fv5urzZW%2fhm8SuWqRTOYlg%3d%3d%26p%3dhttps%253a%252f%252fwww.event-reg.biz%252foem-Koelnmesse%252fOnlineExhListing" which can be URL decoded to: "/oem-Koelnmesse/OnlineExh.aspx?e=/v5urzZW/hm8SuWqRTOYlg==&p=https%3a%2f%2fwww.event-reg.biz%2foem-Koelnmesse%2fOnlineExhListing"
    3. URL "/oem-Koelnmesse/OnlineExh.aspx?e=/v5urzZW/hm8SuWqRTOYlg==&p=https%3a%2f%2fwww.event-reg.biz%2foem-Koelnmesse%2fOnlineExhListing" does a redirect at the server to: "/oem-Koelnmesse/OnlineExh?e=/v5urzZW/hm8SuWqRTOYlg==&p=https%3a%2f%2fwww.event-reg.biz%2foem-Koelnmesse%2fOnlineExhListing", which is the final URL that you would see in the browser.


    You can easily see the flow by intercepting the traffic using fiddler and see it for yourself:
    Fiddler Screenshot