ASP.NET
3. 닷넷 기초 (IP 주소 가져오기)
왕초보코딩탈출
2018. 2. 25. 16:10
IP 주소는 출력에는
localhost / 127.0.0.1 / ::1 이렇게 3가지 방법이 있다 다 같은 것
TEST4.aspx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test4.aspx.cs" Inherits="FrmText.test4" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> </head> <body> <form id="form1" runat="server"> <div> IP 주소 얻기 <br / /> <asp:Label ID="Lable1" runat="server"></asp:Label> <br /> <asp:Label ID="Label2" runat="server"></asp:Label> <br /> <asp:Label ID="Label3" runat="server"></asp:Label> <br /> </div> </form> </body> </html> | cs |
TEST4.aspx.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace FrmText { public partial class test4 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { this.Lable1.Text = Request.UserHostAddress; this.Label2.Text = Request.ServerVariables["REMOTE_HOST"]; this.Label3.Text = Request.ServerVariables["REMOTE_ADDR"]; } } } | cs |