Related Posts Plugin for WordPress, Blogger...

About

Follow Us

Friday, 6 February 2015

Introduction:
Sometime we need to use IP Address of Client System in our application, just for record or for other purpose..
In this article i will explain how to get  IP Address of the client using asp.net. To get the IP Address of the client in ASP.NET , you can use the property UserHostAddress of the current Request object. The following example shows you how to get the IP Address address of a client. I have written the code on the button click event.

C#.Net Code to get IP Address of the client


   protected string GetIPAddress()
    {
        HttpRequest request = HttpContext.Current.Request;
        return request.UserHostAddress;
    }

protected void btnIpAddress_Click(object sender, EventArgs e)
    {
        string ipAddress = GetIPAddress();
        Response.Write("IP Address: " + ipAddress);
    }

VB.NET Code to get IP Address of the client

protected Function GetIPAddress() As String
        Dim request As HttpRequest = HttpContext.Current.Request
        Return request.UserHostAddress
    End Function

Protected Sub btnIpAddress_Click(ByVal sender As Object, ByVal e As System.EventArgs) HandlesbtnIpAddress.Click
        Dim ipAddress As String = GetIPAddress()
        Response.Write("IP Address: " & ipAddress)

End Sub

0 comments:

Post a Comment