프로그래밍/실버라이트

[Silverlight] get Client Ip Address

쿠샨 2012. 3. 16. 15:15


방법 1. Web Service를 이용하는 방법


방법 2. Server Side Script 이용하는 방법





방법 1. 소개
          WcfService 에서 System.Web.HttpContext.Current.Request.UserHostAddress; 를 이용하여 받아 온다. 


          또 다른 방법으로는 아래 글을 참조 하자.
          /* NOTE: This is another way to do it but the one method is more straight forward: 
   if( HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null) 
        CustomerIP = HttpContext.Current.Request.ServerVariable["HTTP_X_FORWARDED_FOR"].ToString(); 
   else if (HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"] != null)                
CustomerIP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString(); 
 */  
          1. HTTP_X_FORWARDED_FRO - This is used to obtain the originating IP address of a client that connected through a proxy.
          2. REMOTE_ADDR - Used to obtain the client IP address if a proxy was not used.



방법 2. 소개
ASP 닷넷 이용.

Page_Load 이벤트에 다음 코드 작성
InitParam = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];

ASP 파일에 다음 코드 작성
<param name="initParams" value="IPAddress=<%=InitParam%>"/> 세팅 asp

Application_Startup 이벤트에 다음 코드 작성
string ipAddress = e.InitParams["IpAddress"];