coding/c#

[C#] Request.ServerVariables 전체 값 확인 (URL, IP주소 등등)

사과키라임파이 2021. 12. 29. 14:06

https://ggmouse.tistory.com/75

 

[C#] Request.ServerVariables 전체 값 확인 (URL, IP주소 등등)

Request Object인 ServerVariables Collection의 전체 값을 확인해보자 ServerVariables의 함수를 사용하여 IP주소, 도메인 주소 등 많은 요소들의 정보를 알아낼 수 있다. // 클라이언트(사용자) IP 주소 (xxx.x..

ggmouse.tistory.com

 

 

ServerVariables의 함수를 사용하여 IP주소, 도메인 주소 등 많은 요소들의 정보를 알아낼 수 있다.

 

// 클라이언트(사용자) IP 주소 (xxx.xxx.xxx.xxx)
Request.ServerVariables["REMOTE_HOST"];
 
// 서버 IP 주소 (xxx.xxx.xxx.xxx)
Request.ServerVariables("LOCAL_ADDR");
 
// 도메인 주소 (ggmouse.tistory.com)
Request.ServerVariables["HTTP_HOST"];
 
// 현재 경로 (/Test/ikTest.aspx)
Request.ServerVariables["PATH_INFO"];

 

 

이외에 전체 요소를 한번에 확인해보자

 

int loop1, loop2;
System.Collections.Specialized.NameValueCollection coll;
 
coll = Request.ServerVariables;
 
String[] arr1 = coll.AllKeys;
 
for (loop1 = 0; loop1 < arr1.Length; loop1++)
{
    Response.Write("<pre> " + arr1[loop1] + "</pre>");
    String[] arr2 = coll.GetValues(arr1[loop1]);
 
    for (loop2 = 0; loop2 < arr2.Length; loop2++)
    {
    Response.Write("<pre>" + Server.HtmlEncode(arr2[loop2]) + "</pre>");
    }
 
    Response.Write("<br>");
}



출처: https://ggmouse.tistory.com/75 [초보개발자꽁쥐]

'coding > c#' 카테고리의 다른 글

C# IsAuthorized  (0) 2021.12.29
C# FormsAuthenticationTicket  (0) 2021.12.29
C# byte[]  (0) 2021.12.21
Encoding.UTF8.GetBytes  (0) 2021.12.20
C# record? struct? class?  (0) 2021.12.20