Created
July 31, 2014 10:43
-
-
Save lski/52744090e73e46bbbc3b to your computer and use it in GitHub Desktop.
Returns the Clients Ip Address from the Request message
This file contains 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
using System.Web; | |
namespace System.Net.Http { | |
public static class HttpRequestMessageExt { | |
/// <summary> | |
/// Returns the Clients Ip Address from the Request message | |
/// | |
/// Note: Use owin context version Request.GetOwinContext().Request.RemoteIpAddress (owin context can also be retrieved from (OwinContext)request.Properties["MS_OwinContext"] | |
/// </summary> | |
public static string GetClientIp(this HttpRequestMessage request) { | |
return (request.Properties.ContainsKey("MS_HttpContext") ? ((HttpContextWrapper)request.Properties["MS_HttpContext"]).Request.UserHostAddress : (string)null); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment