- 1 - ASP.NET 2.0 Web Programming 이현정 hjyi@hotmail.com MCT/MCSD/MCAD/MCSD.NET
목차 1장 3장 ASP.NET 2.0 기초 5장 ASP.NET 2.0 페이지및응용프로그램구조 6장 Visual Studio 2005 둘러보기 7장서버컨트롤사용하기 8장파일다루기 9장데이터베이스와연동하기 10장테마 (Themes) 11장마스터페이지 (Master Pages) 12장사이트탐색 (Site Navigation) 13장보안 (Security) 14장프로필 (Profiles) 15장웹파트 (Web Parts) 16장캐싱 (Caching) 을이용한성능향상 17장다국적웹사이트만들기 18장상태관리 (State Management) 20장웹응용프로그램관리 21장웹응용프로그램모니터링 22장웹사이트배포 - 2 -
- 3-17장다국적웹사이트만들기 다국적웹사이트들어가기 다국적웹사이트구현 자동 Culture 확인기능 전역리소스와지역리소스 암시적지역화 명시적지역화 Localize 컨트롤
2. 다국적웹사이트구현 - 4 - 자동 culture 확인기능 (p619) 웹브라우저의기본설정을기반으로 culture 을선택 웹페이지단위 <%@ Page Culture= auto uiculture= auto %> 웹응용프로그램단위 <configuration> <system.web> <globalization culture= auto uiculture= auto > </system.web> </configuration>
전역리소스와지역리소스 - 5 - 전역리소스 App_GlobalResource 모든페이지에서사용 리소스파일이름임의지정가능 예 :MyResource.resx 지역리소스 -App_LocalResource 해당페이지에서만사용 페이지명.aspx.resx 페이지명.aspx.culture코드.resx 예 : default.aspx.en.resx
암시적지역화 (p622) - 6 - 컨트롤속성에대해일치하는 ResourceKey를기반으로참조 전역리소스는접근힐수없고지역리소스만접근가능 <asp:label ID="Label2" runat="server" meta:resourcekey="label2 /> Default.aspx.ko.resx
명시적지역화 (p623) - 7 - 리소스를검색하는식을만들어리소스파일에있는값을참조 전역리소스와지역리소스모두접근 <asp:label ID="Label1.. Text="<%$ Resources:Label1.Text %> /> <asp:label ID="Label3" Text="<%$ Resources:MyResource, MyKey %> /> 전역리소스 : MyResource.resx 지역리소스 :Default.aspx.ko.resx
Localize 컨트롤 (p624) - 8 - 변하지않는정적콘텐츠를지역화하는데사용되는컨트롤 Copyright문 <asp:localize ID= Localize1... meta:resourcekey= Label2 /> <asp:localize ID= Localize1 Text="<%$ Resources:MyResource, MyKey %> />
- 9-18장상태관리 상태관리들어가기 클라이언트측상태관리옵션 ViewState ControlState HiddenField Cookie QueryString 서버측상태관리옵션 ApplicationState SessionState 데이터베이스
1. 상태관리 ( State Management) 들어가기 - 10 - Without State Management With State Management Login.aspx Login.aspx Please enter your logon information: First Name John Last Name Chen Submit Greetings.aspx Web Server Please enter your logon information: First Name John Last Name Chen Submit Greetings.aspx Web Server Hello Hello John Chen I forget who you are!!
1>ASP.NET2.0 에서제공되는상태관리옵션 - 11 - Server-Side Side State Management Application state Information is available to all users of a Web application Session state Information is available only to a user of a specific session Cookies Client-Side State Management Text file stores information to maintain state The ViewState property Retains values between multiple requests for the same page Profile Property Hidden Field Database In some cases, use database support to maintain state on your Web site Query strings Information appended to the end of a URL
2. 클라이언트측상태관리옵션 - 12 - ViewState Hidden control retains values between multiple requests for the same page Control State Cookies Persistent cookies stored as a text file Query strings Information appended to the end of a URL Hidden fields Field retains values between multiple requests for the same page
1> 뷰상태 (ViewState) - 13 - Server control state is stored in _VIEWSTATE, a hidden control on the.aspx page _VIEWSTATE stores state in a string value of name-value pairs <form name="form1" method="post" action="webform1.aspx" id="form1" runat="server"> <input type="hidden" name=" VIEWSTATE" value="ddw3nze0mtexodq7oz4=" /> 'HTML here </form> Maintain the state of select ASP.NET server controls vs. maintaining the state of all the ASP.NET server controls on a Web Form <%@ Page EnableViewState="False" %> <asp:listbox id="listname" EnableViewState="true" runat="server"></asp:listbox>
뷰상태 (ViewState) - 14 - You can use the ViewState property to store your own state on the client-side. this.viewstate.add("name", txtname.text); // ViewState[ Name ] = txtnam.text; lblname.text = this.viewstate["name ].ToString();
2> 컨트롤상태 (Control State) - 15 - ASP.NET 2.0 에서새로추가 ViewState는임의로해제될수있는반면, 컨트롤상태는임의로해제될수없다. Custom Control 구현시제대로동작하기위해필요 구현시프로그래밍이필요 컨트롤초기화도중에 RegisterRequiresControlState() 를호출 SaveControlState() 와 LoadControlState() 를재정의해야함
3> Hidden Field - 16 - 동일한페이지및페이지간게시에도정보유지 HiddenField 및 HtmlInputHidden 컨트롤 보안에취약, 성능저하 <input type="hidden" / >
3> 쿠키 (Cookie) - 17 - Used to maintain state Temporary/Non-persistent cookies Persistent cookies Less reliable than server-side state management options User can refuse or delete cookies Less secure than server-side state management options Limited amount of information Client-side restrictions on file sizes (4096 bytes) Client Computer Cookie Web Server
쿠키에정보저장 - 18 - Creating a cookie using the Response and Request properties of the Page class HttpCookie objcookie = new HttpCookie("myCookie"); DateTime dt= DateTime.Now; objcookie.values.add("time", dt.tostring()); //objcookie[ Time ]=dt.tostring(); objcookie.values.add("forecolor", "White"); objcookie.values.add("backcolor", "Blue"); objcookie.expires = dt.addhours(1); Response.Cookies.Add(objCookie);
쿠키에서정보읽어오기 - 19 - Read the cookie using Request.Cookies HttpCookie objcookie = Request.Cookies["myCookie ]; Retrieve values from the cookie lbltime.text = objcookie.values("time"); // lbltime.text = objcookie ["Time ]; lbltime.forecolor = System.Drawing.Color.FromName (objcookie.values("forecolor")); lbltime.backcolor = System.Drawing.Color.FromName (objcookie.values("backcolor ));
4> 쿼리문자열 (Query String) - 20 - http://localhost/charpter18/test.aspx?p1=a&p2=1 URL 에서? 이후에나오는문자열 페이지간의정보전달 보안에취약 URL에명시하므로길이제한 string s1 = Request.QueryString[ p1 ]; string s2 = Request.QueryString[ p2 ];
3. 서버측상태관리옵션 - 21 - Application state is a global storage mechanism accessible from all pages in the Web application Session state is limited to the current browser session Values are preserved through the use of application and session variables Scalability ASP.NET session is identified by the SessionID string Client Computer Web Server Application and Session variables SessionID
The Global.asax File - 22 - Only one Global.asax file per Web application Stored in the virtual root of the Web application Used to handle application and session events The Global.asax file is optional
1> 응용프로그램상태 ( Application State) - 23 - 웹응용프로그램모든모든사용자가접근할수있다. 모든세션이공유하는정보저장공간 웹서버메모리에저장 protected void Application_Start(Object sender,eventargs e) { Application["NumberofVisitors"] = 0; } Application.Lock(); Application["NumberOfVisitors"] = (int)application["numberofvisitors"] + 1; Application.UnLock(); lblnbvisitor.text = Application["NumberOfVisitors"].ToString();
2> 세션상태 ( Session Variables) - 24 - Sessions are identified by 120-bit Session ID strings Setting session variables <= Session_Start event Session.Add("BackColor", "blue") ; Session["BackColor ] = "blue ; Reading session variables strbgcolor = Session["BackColor ]; Removing session variables Session.Remove["BackColor ] ;
Session Duration - 25 - Sessions have a set duration time after last access Default is 20 minutes Session duration can be changed in Web.config <configuration> <system.web> <sessionstate timeout="10" /> </system.web> </configuration>
Scalable Storage of Application and Session Variables- 26 - By default, the session state is managed in process Disadvantage of in process storage: Not Scalable ASP.NET provides out of process storage of session state State can be stored in a SQL Server database or a state server Advantages of out of process storage: Scalable Web farm State server -Or- Session and Application variables Client SQL Session and Application variables
Saving Application and Session Variables in a Database- 27 - Web.config에세션상태명시 1 Mode is set to SQLServer or StateServer <sessionstate mode="sqlserver" sqlconnectionstring= "data source=sqlservername; Integrated security=true"/> 2 SQL server 구성 c>aspnet_regsql.exe -S SampleSqlServer -E -ssadd 저장프로시저가포함된 ASPState 라는데이터베이스를만듭니다. 세션데이터자체는기본적으로 tempdb 데이터베이스에저장됩니다.
3> 프로필속성 (Profile Property) - 28 - 사용자설정정보를저장하고참조하는데사용 세션상태와비슷하지만세션이종료되어도남아있다.
- 29-20장웹응용프로그램관리 구성파일 (Configuration File) 관리도구사용
1. 구성파일 (Configuration File) - 30-1> 구성파일이란? 웹서버나웹응용프로그램에대한구성ㅂ정보가들어있는.config 확장자를가지는 XML 파일 Machine.config file - Machine-level settings - Only one Machine.config file per Web server Web.config files - Application and directory-level settings Both Machine.config and Web.config files are: Well-formed XML camelcase Extendable
Understanding Configuration Inheritance - 31 - CONFIG Machine.config Application-level Web.config file inherits settings from Machine.config file VirtualDir SubDir Web.config Web.config Settings in Web.config file that conflict override inherited settings Individual directories may have Web.config files that inherit from and can override application-level settings
구성정보 - 32 - <anonymousidentification> <appsettings> <configuration> <appsettings> <add key="pubs" value="server=localhost; integrated security=true; database=pubs"/> <add key= FilePath1 value= \Files\MyFile /> </appsettings> </configuration> string strpubs = ConfogurationManager.AppSettings["pubs ]; string strfilepath = ConfogurationManager.AppSettings[ FilePath1 ]; <authentication> <authorization> <caching> <compilation>
구성정보 - 33 - <httpruntime> <memebrship> <pages> <profile> <rolemanager> <sessionstate> <sitemap> <webparts>
2. 관리도구사용 - 34 - ASP.NET 2.0 에서제공하는웹응용프로그램관리도구 ASP.NET MMC 스냅인 - 시작 프로그램 - 관리도구 - 인터넷서비스관리자 - 우베사이트선택하여 등록정보 - ASP.NET 탭 웹사이트관리도구 - Visual Studio 웹사이트 ASP.NET 구성 aspnet_regsql.exe - ASP.NET 응용프로그램기능에서상요하는미리구성된 SQL Server 데이터베이스를설치 aspnet_regiis.exe - 로컬컴퓨터에 ASP.NET 을설치하고제거하는관리도구
- 35-21장웹응용프로그램모니터링 추적 (Trace) Tracing Page-level Tracing Application-level Tracing 오류처리 (Error Handling)
Trace Object - 36 - Inserting trace messages Trace.Write ("category", "message"); Trace.Warn ("category", "message"); Conditional execution with Trace.IsEnabled If (Trace.IsEnabled) { strmsg = "Tracing is enabled! ; Trace.Write("myTrace", strmsg); } Dynamically change state of trace Trace.IsEnabled = False;
페이지추적 (Page-level Trace) - 37 - Page-level tracing displays trace statements only on the configured page Enabling page-level tracing <%@ Page Language="c#" Trace="true" %>
Viewing Trace Results - 38 -
응용프로그램추적 (Application-level Tracing) - 39 - Application-level tracing displays trace information for all pages in a Web application Enabling application-level tracing in the Web.config file <trace enabled="true" pageoutput="true" localonly="true"/> Set pageoutput=false in the Web.config file and trace results are viewable by trace viewer http://server/project/trace.axd
Application-Level Trace - 40 - Page Trace=True Trace=False Application Trace=True or Trace=False Trace=True or Trace=False Result Trace results are displayed on page Trace results are not displayed Trace not set Trace=True Trace results are displayed on page Application-level trace statements are displayed on individual pages
Tracing into a Component - 41 - Import the System.Web Library using System.Web; Enable Tracing HttpContext.Current.Trace.IsEnabled = true; Call Trace methods HttpContext.Current.Trace.Write ("component", "this is my trace statement");
오류처리 (Error Handling) - 42 - 오류처리 구성오류 파서오류 컴파일오류 디버그모드활성화 페이지단위디버그모드활성화 <%@ Page Debug="true" %> 응용프로그램단위디버그활성화 (web.config) <configuration> <system.web> <compilation debug= true /> </system.web> </configuration>
Remote Debugging - 43 - Remote debugging: Debug Web applications remotely Simplifies team development Simplifies Web site management Requirements for remote debugging: Requires Visual Studio.NET or remote components on the server Visual Studio.NET must be installed on the client Requires administrative access to the server Requires access for the user who is performing debugging
- 44-22장웹사이트배포 웹사이트배포들어가기 웹사이트복사도구 웹사이트게시유틸리티
1. 웹사이트배포들어가기 - 45 - 웹사이트배포란? 개발된웹사이트를실제운영서버, 프로덕션서버 ( 운영서버 ) 에올리는작업 웹사이트복사도구 웹사이트게시유틸리티
2> 웹사이트복사도구 - 46 - IIS에배포할프로덕션사이트를만들어야한다 Visual Studio2005- 웹사이트 웹사이트복사메뉴
3> 웹사이트게시유틸리티 - 47 - 미리컴파일 (Precompliation) 하여웹사이트에배포 Visaul Studio 2005- 빌드 웹사이트게시메뉴
- 48-23 장 Tips & Tricks 일반팁 Focus API 다시게시후스크롤위치유지하기 성능향상팁 비컴파일페이지만들기 (No-Compile Pages) 뷰상태사용자제 서버컨트롤사용자제 DataSet vs. DataReader
- 49 - ASP.NET 2.0 실전예제 24 장 GridView 를이용한게시판만들기 Aspnetdb 변경 (p745- ) \ chap24\ App_Data\ board_add.sql 25 장 GridView 를이용한답변게시판만들기 26 장자료실만들기 27 장설문조사 역할만들기및관리 (p840 - ) 28 장완전한웹사이트만들기 \ chap28\ App_Data\ website- add.sql