ASP.NET

10.C# ASP.NET - Request.UserHostAddress

Godffs 2009. 10. 5. 14:53
반응형
원격 접속자 클라이언트의 IP 호스트 주소를 가져오는 예제입니다.

RequestUserHostAddress.cs

<div>

   현재 접속자의 IP주소 얻기<br />

   <br />

   <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

   <br />

   <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>

   <br />

   <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>

</div>


RequestUserHostAddress.aspx.cs

protected void Page_Load(object sender, EventArgs e)

{

    //현재 접속자의  IP주소를 얻는 3가지 방법

    this.Label1.Text = Request.UserHostAddress;

   

    //ASP.NET 2.0에서 사용됨

    Label2.Text = Request.ServerVariables["REMOTE_HOST"];

    Label3.Text = Request.ServerVariables["REMOTE_HOST"];

}


결과화면

[그림10-1]



반응형