How would you read the following server variables in an ASP.NET Web API controller?
HTTP_HOST
SERVER_NAME
REMOTE_HOST / REMOTE_ADDR
I see a System.Net.Http.HttpRequestMessage Request defined, but I don't see a collection containing these variables.
I'm running a website on a single IP with multiple host headers and I need to determine which site they used to get there.
EDIT:
It ended up being something like this:
((System.Web.HttpContextWrapper) Request.Properties["MS_HttpContext"])
.Request.ServerVariables["HTTP_HOST"]
The information you are looking for is dependent on the host you are using and Web API is designed to be host independent. So.... the information you are looking for will be buried in the httpRequestMessage.Properties collection and it will be different depending on your host.
If you move to using the Owin adapter then you will get a standardized Owin environment object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With