protected static string GetUserIPAddress()
{
string VisitorsIPAddr = string.Empty;
if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
{
VisitorsIPAddr = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
}
else if (System.Web.HttpContext.Current.Request.UserHostAddress.Length != 0)
{
VisitorsIPAddr = System.Web.HttpContext.Current.Request.UserHostAddress;
}
return VisitorsIPAddr;
}
Monday, February 3, 2014
How to get visitor IP address in static method?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment