개발/C#
ASP.net 클라이언트IP 얻기
혈중마라농도
2022. 1. 6. 16:32
public static string GetClientIP()
{
try
{
HttpContext hc = HttpContext.Current;
if (hc == null)
return string.Empty;
string ipList = hc.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (!string.IsNullOrWhiteSpace(ipList))
{
return ipList.Split(',')[0];
}
return hc.Request.ServerVariables["REMOTE_ADDR"];
}
catch(Exception ex) {
Console.Write(ex.ToString());
}
return string.Empty;
}
반응형