Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI all can anyone help me out how to get the client ip address in asp.net web application


thank you in advanvce
Posted

Request.ServerVariables["REMOTE_ADDR"].ToString();
 
Share this answer
 
C#
Request.ServerVariables("REMOTE_ADDR")
or
Request.UserHostAddress
 
Share this answer
 
You can get it using Request.ServerVariables["REMOTE_ADDR"] or Request.ServerVariables["HTTP_X_FORWARDED_FOR"].
See this function:
C#
public static string GetIPAddress()
{
    System.Web.HttpContext context = System.Web.HttpContext.Current;
    string sIPAddress = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
    if (string.IsNullOrEmpty(sIPAddress)) {
        return context.Request.ServerVariables["REMOTE_ADDR"];
    } else {
        string[] ipArray = sIPAddress.Split(new Char[] { ',' });
        return ipArray[0];
    }
}



--Amit
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900