visibility 18 comment 0 access_time 25 days ago language English

codeASP.NET Core Find out Page Referer

Referer is usually sent as part of HTTP request headers. For instance, the Referer field in HTTP request header can look like the following:


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();
fork_right Fork
copyright This page is subject to Site terms.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

comment Comments
No comments yet.