/// <summary>
/// GetRealIP获得外网和内网IP
/// </summary>
/// <returns></returns>
public static string GetRealIP()
{ // String ClientIP; // //
ClientIP = Request.UserHostAddress; // //
IPHostEntry myHost = Dns.GetHostByAddress(Request.UserHostAddress); // // string UserHostName; // //
UserHostName=myHost.HostName;
string ip;
try
{
HttpRequest request = HttpContext.Current.Request;
if (request.ServerVariables["HTTP_VIA"] != null)
{
ip = request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString().Split(',')[0].Trim(); }
else
{
ip = request.UserHostAddress;
}
}
catch (Exception ex)
{
throw ex;
}
return ip;
}
/// GetRealIP获得外网和内网IP
/// </summary>
/// <returns></returns>
public static string GetRealIP()
{ // String ClientIP; // //
ClientIP = Request.UserHostAddress; // //
IPHostEntry myHost = Dns.GetHostByAddress(Request.UserHostAddress); // // string UserHostName; // //
UserHostName=myHost.HostName;
string ip;
try
{
HttpRequest request = HttpContext.Current.Request;
if (request.ServerVariables["HTTP_VIA"] != null)
{
ip = request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString().Split(',')[0].Trim(); }
else
{
ip = request.UserHostAddress;
}
}
catch (Exception ex)
{
throw ex;
}
return ip;
}