I have an MVC WebAPI 2 project with a Controllers
controller. The Method I'm trying to call is POST
(Create). I need to access the referring URL that called that method yet, no matter what object I access, the referring URL either doesn't exist in the object or is null.
For example, I've added the HTTPContext
reference and the following returns null
:
var thingythingthing = HttpContext.Current.Request.UrlReferrer;
The Request
object does not have a UrlReferrer
property.
This returns null as well:
HttpContext.Current.Request.ServerVariables["HTTP_REFERER"]
I cannot modify the headers because I need to be able to generate a link to the method and filter access by origin of the call.
Any particular place I should be look or, alternatively, any particular reason why those are returning null?
Edit: I have a solution for GET methods (HttpContext.Current.Request.RequestContext.HttpContext.Request.UrlReferrer
) but not for POST methods.