posted 3/29/2009 by Sumit Arora
Many times there can be a situation where we require the IP address of a user.For ex while placing an order on Shopping portal we need the IP address for security purposes.Below is the code of how to find users IP address in ASP.NET.
public string FindIPAddress(){ try { HttpRequest currentRequest = HttpContext.Current.Request; string ipAddress = currentRequest.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (ipAddress == null || ipAddress.ToLower() == "unknown") ipAddress = currentRequest.ServerVariables["REMOTE_ADDR"]; return ipAddress; } catch (Exception ex) { }}
This comment is awaiting moderation.
Not Easy Like
value = Request.ServerVariables("remote_host")
What kind of email newsletter would you prefer to receive from CodeAsp.Net?18