Skip to content

Instantly share code, notes, and snippets.

@jacobmendoza
Created November 8, 2012 12:57
Show Gist options
  • Save jacobmendoza/4038650 to your computer and use it in GitHub Desktop.
Save jacobmendoza/4038650 to your computer and use it in GitHub Desktop.
Access to base request in WebApi to retrieve client IP
var baseRequest = ((HttpContextWrapper)request.Properties["MS_HttpContext"]).Request;
var remoteDir = baseRequest.ServerVariables["REMOTE_ADDR"];
var directionsOfRedirection = baseRequest.ServerVariables["X_FORWARDED_FOR"];
return remoteDir ?? directionsOfRedirection;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment