ASP.NET Core Find out Page Referer
Code description
Referer is usually sent as part of HTTP request headers. For instance, the Referer field in HTTP request header can look like the following:
Referer: https://kontext.tech/
This code snippet provides example of retrieving referer information via HttpRequest.GetTypedHeaders
method in ASP.NET Core Razor pages. It also shows you how to get the relative path and query string only. The same code can also be used in web API controllers.
Note: The referer can be NULL if user directly type the page URL in browser.
Code snippet
public IActionResult OnGet() { var headers = Request.GetTypedHeaders(); var referer = headers.Referer; var refererRelativePath = referer?.PathAndQuery; return Page(); }
copyright
This page is subject to Site terms.
comment Comments
No comments yet.