You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
717 B
23 lines
717 B
using Microsoft.Owin;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Web;
|
|
|
|
namespace Common.Utility
|
|
{
|
|
public class GetClientIpAddress
|
|
{
|
|
public string GetIpAddress(HttpRequestMessage request)
|
|
{
|
|
if (request.Properties.ContainsKey("MS_HttpContext"))
|
|
{
|
|
return IPAddress.Parse(((HttpContextBase)request.Properties["MS_HttpContext"]).Request.UserHostAddress).ToString();
|
|
}
|
|
if (request.Properties.ContainsKey("MS_OwinContext"))
|
|
{
|
|
return IPAddress.Parse(((OwinContext)request.Properties["MS_OwinContext"]).Request.RemoteIpAddress).ToString();
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
}
|