Adsence750x90

Friday, April 9, 2010

Get Client IP Address ASP.NET

How to get IP Host Address of remote Client

 // To get IP of the client meachine
        // There is two methods to obtain IP address
       
        // Method 1
        //     Gets the IP host address of the remote client.
        // Returns:
        //     The IP address of the remote client.
        string ipMethod1 = Request.UserHostAddress; // HttpContext.Current.Request.UserHostAddress;

        //Methord 2
        //Request.ServerVariables is a Name Value Collection
        //     Gets a collection of Web server variables.
        // Returns:
        //     A System.Collections.Specialized.NameValueCollection of server variables.
        string ipMethod2 = Request.ServerVariables["REMOTE_ADDR"]; //HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
        Response.Write(ipAdddress);

2 comments:

Clover said...

This is really a great read for me. Thank you for publishing articles having a great insight stimulates me to check more often for new write ups. Keep posting!

Clover
www.n8fan.net

Unknown said...

They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety. See the link below for more info.


#obtain
www.ufgop.org