Since Google sends you to this post when searching for the C# Web API Referrer there is a deal: the Web API uses a different Request type from a regular MVC Request called HttpRequestMessage , which does not include UrlReferrer . Since a regular Web API request does not include this information, if you really need it, you must have your clients to enable it. Although you can make this part of your API Object , it is better to use Headers .
First, you can extend HttpRequestMessage to provide the UrlReferrer() method:
public static string UrlReferrer(this HttpRequestMessage request) { return request.Headers.Referrer == null ? "unknown" : request.Headers.Referrer.AbsoluteUri; }
Then your customers need to install the Referrer Header in their API Request :
// Microsoft.AspNet.WebApi.Client client.DefaultRequestHeaders.Referrer = new Uri(url);
And now the Web API Request includes referrer data that can be accessed from this Web API :
Request.UrlReferrer();
Serj Sagan Sep 08 '15 at 5:47 2015-09-08 05:47
source share