Hi Team,
I am getting an error as " HttpContext does not contain a definition for Current"
private string ClientIP()
{
string ipAddress = string.Empty;
try
{
string strHostName = HttpContext.Current.Request.UserHostAddress.ToString();
ipAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
}
catch (Exception ex)
{
}
finally
{
}
return ipAddress;
}
Please assist me as what need to be added instead of Current ?

Arnab MukherjeePosted Jul 9, 2021, 10:43 AM
Sachin SinghPosted Jul 9, 2021, 10:41 AM
@Saumya
HttpContext.Connection is a property that helps to Get information about the underlying connection for the current request.
applicable to .net core 2.1, 1.0, 1.1, 2.0, 2.2, 3.0, 3.1, 5.0
Namespace: Microsoft.AspNetCore.Http
Assembly: Microsoft.AspNetCore.Http.Abstractions.dll
Package: Microsoft.AspNetCore.App.Ref v5.0.0
Sowmya SirsiPosted Jul 9, 2021, 10:35 AM
@ Sachin
I am using .net core
string strHostName = HttpContext.Connection.RemoteIpAddress;
getting and error "object doesnot contain and definition for connection no accessible method for connection."
What connection are using here?
Sachin SinghPosted Jul 9, 2021, 8:45 AM
Arnab MukherjeePosted Jul 9, 2021, 6:48 AM