Find client IP Address of user in Asp.net C#?
Finding the User Machine IP is a very basic thing. Why would it become a necessity? It starts when a developer builds an application where they need to track the status of visitor that is viewing its application. At that, time knowing the user Machine IP becomes a matter of security and identifying the user location.
Let’s see some direct way in which we can find the IP Address.
1: Create a New Website. Add a Web Form (GetIPAddress.aspx).
2: Add a new Web Form. Prepare a layout design with 2 Label controls.
Asp.net code find client IP Address of user in Asp.net C#
Web Form (Source Code)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GetIPAddress.aspx.cs"Inherits="GetIPAddress" %>
<!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 runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div style="width:190px; height:180px; border:7px groove; padding-left:20px;">
<h3 style="color:Orange; font-weight:bold;"><u>GET IP ADDRESS</u></h3>
<br />
<asp:Label ID="Label1" runat="server" Text="Label-1" Font-Bold="true"ForeColor="Green"></asp:Label><br />
<asp:Label ID="Label2" runat="server" Text="Label-2" Font-Bold="true"ForeColor="Chocolate"></asp:Label>
</div>
</form>
</body>
</html>
3: Debug(CTRL+SHIFT+B). Check for compile error if any.
4: On Build succeeded. Run(CTRL+F6).
5: See the output window. Both labels are shown.
Related Post :
|
|
|
|
|
|
|
|
|
Comments
Post a Comment