Search code examples
c#asp.nethttprequest

How to get the url of the page from which a Post request was triggered?


Lets say that I am no https://localhost/My-cool-page?color=blue&brand=ferrari and from that page I make a post request to my backend https://localhost/api/getCars

how do I from the http request find out that the request came from the page https://localhost/My-cool-page?color=blue&brand=ferrari

and not localhost as the origin of the httprequest states?


Solution

  • I think you are looking for the referer. You can do this

    string referer = Request.Headers["Referer"].ToString();