file name : how-to-Get-client-IP-address.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="how-to-Get-client-IP-address.aspx.vb"Inherits="how_to_Get_client_IP_address" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>How to Get the client IP address</title>
</head>
<body>
<form id="form1" runat="server">
<div>
Your IP Address :
<asp:Label ID="Label1" runat="server" Text="Label" Width="150px"
BackColor="#3399FF" BorderColor="Red" BorderStyle="Dotted" ></asp:Label>
</div>
</form>
</body>
</html>
File Name: how-to-Get-client-IP-address.aspx.vb
Partial Class how_to_Get_client_IP_address
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ClientIP As String
ClientIP = Request.UserHostAddress
Label1.Text = ClientIP
End Sub
End Class
note. unless it your local lan, this will not be the true ipaddres of the client, but the nat address given by the isp. also if you webserver is behind a firewall, then it will be the firewalls ipaddress. in this case the firewall should have added a hostheader
with the ipaddress. see your firewall docs.
me0pro
Member
76 Points
76 Posts
How to get client IP
Feb 18, 2012 02:45 PM|LINK
How to obtain the real IP of the client??
AccuWebHosti...
Contributor
2212 Points
401 Posts
Re: How to get client IP
Feb 18, 2012 03:21 PM|LINK
Hi!
here is the code:
file name : how-to-Get-client-IP-address.aspx <%@ Page Language="VB" AutoEventWireup="false" CodeFile="how-to-Get-client-IP-address.aspx.vb"Inherits="how_to_Get_client_IP_address" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>How to Get the client IP address</title> </head> <body> <form id="form1" runat="server"> <div> Your IP Address : <asp:Label ID="Label1" runat="server" Text="Label" Width="150px" BackColor="#3399FF" BorderColor="Red" BorderStyle="Dotted" ></asp:Label> </div> </form> </body> </html> File Name: how-to-Get-client-IP-address.aspx.vb Partial Class how_to_Get_client_IP_address Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim ClientIP As String ClientIP = Request.UserHostAddress Label1.Text = ClientIP End Sub End ClassThanks
Top Windows VPS Provider
abiruban
All-Star
16072 Points
2736 Posts
Re: How to get client IP
Feb 18, 2012 04:04 PM|LINK
Hi
should work - either directly in a view or in the controller action method body (Request is a property of Controller class in MVC, not Page).http://stackoverflow.com/questions/2717702/how-do-you-get-the-users-ip-address-in-castle-mvc-monorail
http://stackoverflow.com/questions/2577496/how-can-i-get-the-clients-ip-address-in-asp-net-mvc
***DON'T FORGET TO CLICK “MARK AS ANSWER” ON THE POST IF HELPED YOU.
mishra.bhupe...
Participant
1596 Points
378 Posts
Re: How to get client IP
Feb 18, 2012 04:19 PM|LINK
String hst = Dns.GetHostName();
IPAddress[] ip = Dns.GetHostAddresses(hst);
Texbox1.Text = ip[0].ToString();
bruce (sqlwo...
All-Star
36882 Points
5451 Posts
Re: How to get client IP
Feb 19, 2012 12:18 AM|LINK
note. unless it your local lan, this will not be the true ipaddres of the client, but the nat address given by the isp. also if you webserver is behind a firewall, then it will be the firewalls ipaddress. in this case the firewall should have added a hostheader with the ipaddress. see your firewall docs.
me0pro
Member
76 Points
76 Posts
Re: How to get client IP
Feb 19, 2012 01:39 PM|LINK
Request.UserHostAddress in mvc4 does not pass.
me0pro
Member
76 Points
76 Posts
Re: How to get client IP
Feb 19, 2012 01:41 PM|LINK
I made the value of IP ::: 1
me0pro
Member
76 Points
76 Posts
Re: How to get client IP
Feb 19, 2012 01:49 PM|LINK
Is it because of the work under mvc4?