September 5, 2016 23:20 by Dan
Here we will learn how to get users / client IP address in asp.net using c# and vb.net with example or retrieving user's IP address in asp.net using c# and vb.net or how to get IP address of visitors machine in asp.net using c# and vb.net with example.
To get user / client ip address of machine in asp.net first create new application in visual studio then open aspx page and write the code as shown following.
<title>Get visitors machine IP in asp.net</title>
<form id="form1" runat="server">
<asp:Label ID="lblIP" runat="server" Font-Bold="true" Font-Size="XX-Large" ForeColor="#529E00"/>
Now open code behind file and write the code like as shown below
protected void Page_Load(object sender, EventArgs e)
string IPAdd = string.Empty;
IPAdd = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
IPAdd = Request.ServerVariables["REMOTE_ADDR"];
lblIP.Text = IPAdd;
Partial Class Default
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim IPAdd As String = String.Empty
IPAdd = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If String.IsNullOrEmpty(IPAdd) Then
IPAdd = Request.ServerVariables("REMOTE_ADDR")
lblIP.Text = IPAdd
If you observe above code when users ip address behind the proxies or routers then REMOTE_ADDR will return IP Address of router, not the user’s machine IP because of that first we need to check with HTTP_X_FORWARDED_FOR. In case if users machine IP address behind a proxy server then his machine’s IP Address will appended to Proxy Server’s IP Address.
Best ASP.NET Hosting Recommendation
ASPHostPortal.com provides its customers with Plesk Panel, one of the most popular and stable control panels for Windows hosting, as free. You could also see the latest .NET framework, a crazy amount of functionality as well as Large disk space, bandwidth, MSSQL databases and more. All those give people the convenience to build up a powerful site in Windows server. ASPHostPortal.com offers ASP.NET hosting starts from $1/month only. They also guarantees 30 days money back and guarantee 99.9% uptime. If you need a reliable affordable ASP.NET Hosting, ASPHostPortal.com should be your best choice.