Created
March 11, 2014 15:28
-
-
Save Injac/9488161 to your computer and use it in GitHub Desktop.
WebApiThrottleChange
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected IPAddress GetClientIp(HttpRequestMessage request) | |
{ | |
if (request.Properties.ContainsKey("MS_HttpContext")) | |
{ | |
IPAddress ipAddress; | |
var ok = IPAddress.TryParse(((HttpContextBase)request.Properties["MS_HttpContext"]).Request.UserHostAddress,out ipAddress); | |
if(ok) | |
{ | |
return ipAddress; | |
} | |
} | |
if (request.Properties.ContainsKey(RemoteEndpointMessageProperty.Name)) | |
{ | |
IPAddress ipAddress; | |
var ok = IPAddress.TryParse(((RemoteEndpointMessageProperty)request.Properties[RemoteEndpointMessageProperty.Name]).Address, out ipAddress); | |
if(ok) | |
{ | |
return ipAddress; | |
} | |
} | |
if (request.Properties.ContainsKey("MS_OwinContext")) | |
{ | |
IPAddress ipAddress; | |
var ok = IPAddress.TryParse(((Microsoft.Owin.OwinContext)request.Properties["MS_OwinContext"]).Request.RemoteIpAddress, out ipAddress); | |
if (ok) | |
{ | |
return ipAddress; | |
} | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment