1
.NET
sln csproj dll cs aspx 說 料 料 利 來 料 ( 來 )
利 [] [] 來 說 切 切 理
[] [ ] 來 說 拉 類 類
[] [ ] 列 連
Web 行流 來 了 不 不 不 流 立 行
Page 類 Load 理 Click 滑
料 Response 列 料 Response HttpResponse 類 Write 料 Redirect URL Response.Write("!! ives!!"); Response.Redirect("WebForm2.aspx");
(1)
(2) Web Form
aspx
例 sample1-a1 (1) WebForm2.aspx WebForm2.aspx 列 WebForm1.aspx private void Page_Load(object sender, System.EventArgs e) { Response.Redirect("WebForm2.aspx"); }
例 sample1-a1 (2) WebForm2.aspx private void Page_Load(object sender, System.EventArgs e) { Response.Write("!! 臨!!"); }
練 sample1-b1 列 " " 行列 " XXX" 念 HTML 行 <br> 列 行
錄 (1) Web (C:\Inetpub\wwwroot) 料 錄 錄 [ ] [ 理 ] [Internet Information Services]
錄 (2) Internet Information Services 料 [ ] 錄
錄 (3) [ ] 立 錄
錄 (4) 錄 錄 URL http://localhost/aspnet/
錄 (5) 錄
錄 (6)
錄 (7) 錄
立 錄 (1) 錄 錄 錄 錄 列
立 錄 (2) IIS 錄 料 []
立 錄 (3) [ 立 ] 錄 立
行 例 (1) 行 例 更 例 (.sln) (.csproj.webinfo) 錄 例 行 例 sample5-b6 D:\ 行 URL http://localhost/sample/
行 例 (2) 立 錄 sample
行 例 (3) 立 錄 錄 D:\sample5-b6
行 例 (3) 錄 錄 sample
行 例 (4) (.csproj.webinfo) Web URLPath 路
行 例 (5) (.sln) 若 例 立 不
行 例 (6) 行 例 利 例 行 行 若 不 更 例 URL IIS 立 例 URL 錄
練 ch1a 例 錄 ch1a 例 念 錄 (.sln) (.csproj.webinfo)
Response BufferOutput 料 Cache Cookies cookie Write 料 Redirect URL Clear 料 Flush 料
例 sample1-a2 (1) private void Hello() { Response.Write("!!<br>"); Response.Flush(); Response.Write(" Ives!!<br>"); Response.Clear(); }
例 sample1-a2 (2) private void Page_Load(object sender, System.EventArgs e) { Response.Write(" <br>"); Hello(); } Response.Write("<br> <br>"); Response.BufferOutput = false; Hello();
Label Label 來 Text ForeColor Visible
Button Button Text Visible Click
MSDN Library MSDN Library 量 例 參 列 [ 說 ] [] [ 索 ] [] 來 MSDN Library 了 類 類 利 F1 http://msdn.microsoft.com/library/ http://msdn.microsoft.com/library/cht/
例 sample1-a3 列 private void submitbtn_click(object sender, system.eventargs e) { string[] fatestr = new string[5] {""," "," "," ",""}; Random rnd = new Random(); fatelb.text = fatestr[rnd.next(0,5)]; }
TextBox TextBox 料 Text ReadOnly MaxLength 度 TextMode SingleLine 行 MultiLine 行 Password TextChanged 更
練 sample1-b2 易 留 料 念 立 利 料 利 Response.Redirect 料
料 理 不 錄 料 行 錄 料 URL 參數 Cookie Session
Request Request HttpRequest 類 Cookies cookie Form 行 post 料 QueryString get 料 QueryString 錄 料 Response.Redirect("abc.aspx?name=ives") 料 Request.QueryString["name"]
例 sample1-a4 (1) WebForm1.aspx private void rightbtn_click(object sender, System.EventArgs e) { Response.Redirect("WebForm2.aspx?ans=yes"); } private void wrongbtn_click(object sender, System.EventArgs e) { Response.Redirect("WebForm2.aspx?ans=no"); }
例 sample1-a4 (2) WebForm2.aspx private void Page_Load(object sender, System.EventArgs e) { if(request.querystring["ans"]=="yes") Response.Write("!! 了!!"); else Response.Write("!! 了!!"); }
練 sample1-b3 易 列 念 利 Request.QueryString 來
Page 類 IsPostBack 料 Session session Load 理 IsPostBack if(!ispostback) {... }
Cookie 念 Cookie Cookie
Cookie 利 Request 來 來 Cookie Response 來 Cookie 讀 Cookie Request.Cookies[ "Cookie " ].Value Cookie Cookie Response.Cookies[ "Cookie " ].Value Cookie Response.Cookies ["Cookie " ].Expires Cookie DateTime.MaxValue; DateTime.Now.AddMonths(2); ( Cookie DateTime.Now)
例 sample1-a5 (1) 錄 數 private void Page_Load(object sender, System.EventArgs e) { if(request.cookies["count"]==null) { Response.Cookies["count"].Value = "0"; }
例 sample1-a5 (2) } else { Response.Cookies["count"].Value = (int.parse(request.cookies["count"].value)+1).tostring(); } Response.Cookies["count"].Expires = DateTime.MaxValue; Response.Write(" 臨!! "); Response.Write(Response.Cookies["count"].Value); Response.Write(" 參!!");
練 sample1-b4 易 錄 欄 念 利 Cookie 來 錄 Cookie 利 IsPostBack
Session 念 連 Session ID 料 料 Server Request 都 Session ID Server ID 來索 Session
Session Session.SessionID 來識 Session ID Session.Timeout Session () Session.Clear() Session Session.Add(string name, object value) Session
Session 立 Session.Add(string name, object value) Session.Add("name", "Alice"); Session["name"] = "Alice"; Session[string name] Label1.Text = Session["name"].ToString();
例 sample1-a6 (1) 列 WebForm1.aspx private void loginbtn_click(object sender, System.EventArgs e) { if((idtb.text == "alice" && pwtb.text == "alice") (idtb.text == "bob" && pwtb.text == "bob")) { Session.Add("id",idTB.Text); Response.Redirect("WebForm2.aspx"); } }
例 sample1-a6 (2) WebForm2.aspx private void Page_Load(object sender, System.EventArgs e) { Response.Write(Session["id"].ToString()); Response.Write(" 臨!!"); }
列 列 WebForm2.aspx 不 若 離 Session
練 sample1-b5 列 念 Session 不 Session 料
(1) 了!? Session 利
(2) Response.Cache.SetNoStore(); 不 Page_Load
練 sample1-b6 sample1-b5 " " 念 利 Response.Cache.SetNoStore();
Application Application HttpApplicationState 類 來 數 Cookie Session Application Application 狀 料 Applicaion 狀 料 Application.Lock(); 料 Application[ "" ]; Application.UnLock();
例 sample1-a7 (1) 數 private void Page_Load(object sender, System.EventArgs e) { count1lb.text = initialstate("item1"); count2lb.text = initialstate("item2"); }
例 sample1-a7 (2) private string initialstate(string itemname) { if(application[itemname] == null) { Application.Lock(); Application[itemName] = 0; Application.UnLock(); } return Application[itemName].ToString(); }
例 sample1-a7 (3) private void order1btn_click(object sender, System.EventArgs e) { count1lb.text = updatestate("item1"); } private void order2btn_click(object sender, System.EventArgs e) { count2lb.text = updatestate("item2"); }
例 sample1-a7 (4) private string updatestate(string itemname) { Application.Lock(); Application[itemName] = int.parse(application[itemname].tostring()) + 1; Application.UnLock(); } return Application[itemName].ToString();
練 sample1-b7 錄 參 數 念 利 Application 來 數