C# .Net
Server 객체
ravon
2011. 7. 13. 11:30
Server 객체는 웹 프로그래밍을 개발할 때 필요한 유틸리티 기능을 모아놓은 객체입니다.
Server 객체는 Page 객체에 정의된 속성 멤버 입니다. HttpServerUtility 클래스를 선언한 것이며, 이미
인스턴스가 생성되어 있으므로 바로 Server 객체를 사용할 수 있습니다.
멤버 설명
MachineName 웹 서버 이름을 알려줍니다.
ScriptTmeOut 웹 페이지 타음아웃을 지정합니다. (디폴트 : 90초)
예) Server.ScriptTimeOut = 90;
MaPath() 가상디렉토리에 해당하는 실제 물리적 경로를 알려줍니다.
예) string path = Server.MapPath("/aspx")
UrlEncode 주어진 문자열을 URL 인코딩합니다.
예) string url = Server.UrlEncode("100%");
HtmlEncode 주어진 문자열을 HTML 인코딩합니다.
예) string url = server.HtmlEncode("<font>");
디렉토리 구하기
<h4> 물리적 디렉토리 경로 구하기 </h4>
<hr>
<br> 현재 ASP가 있는 디렉토리 (.) : <b><%= Server.MapPath(".") %></b>
<br> ASP가 있는 상위 디렉토리 이름 (..) : <b><%= Server.MapPath("..") %></b>
<br> 홈 디렉토리 경로 (/) : <b><%= Server.MapPath("/") %></b>
<br> 디렉토리 경로(/aspx) : <b><%= Server.MapPath("/aspx") %></b>
URL 인코딩.
<% string url = "default.aspx?msg=";
url += Server.UrlEncode( "H&B : 100%" );
%><a href="<%=url%>"> 클릭하세요 </a> ( Encoding : <b>"<%=url%>"</b> )
Request["msg"] : <b>"<%= Request["msg"] %>"</b>
HTML 인코딩
<%
string arg = Server.HtmlEncode( "<font size=2> msg </font>" );
Response.Write( arg );
%>