5 Mart 2012, PAZARTESİ
Uzak ana bilgisayarın IP adresini almak
ASP.NET bize REMOTE_ADDR
özellik değeri IP adresi sağlayan ServerVariables
özellik içeren System.Web.HttpRequest
bir sınıf yoktur.
Ancak, ASP.NET Web API, uzak ana bilgisayarın IP adresini almak için benzer bir yol bulamadım.
Nasıl istekte uzak ana bilgisayarın IP adresini alabilir miyim?
CEVAP
5 Mart 2012, PAZARTESİ
Bu mümkün, ama çok keşfedilebilir - tesiste, marketten gelen istek ve özelliği gereken erişim bağlı olup olmadığını kullanıyorsun Web API altında IIS (webhosted) ya da kendi kendine ev sahipliği yaptı. Aşağıdaki kod, bunun nasıl yapılacağını gösterir.
private string GetClientIp(HttpRequestMessage request)
{
if (request.Properties.ContainsKey("MS_HttpContext"))
{
return ((HttpContextWrapper)request.Properties["MS_HttpContext"]).Request.UserHostAddress;
}
if (request.Properties.ContainsKey(RemoteEndpointMessageProperty.Name))
{
RemoteEndpointMessageProperty prop;
prop = (RemoteEndpointMessageProperty)request.Properties[RemoteEndpointMessageProperty.Name];
return prop.Address;
}
return null;
}
Bunu Paylaş:
Nasıl docker konteyner içinden docker ...
Nasıl enlem ve boylam tam adresini alm...
Benim C sunucusunun IP adresini almak ...
Makinenin IP adresini almak...
Belirli bir uzak bir Git deposundan ta...