ASP NET 2010 ASP NET 2010 ASP NET
- Slides: 62
ASP. NET 2010 ASP. NET - 2010
До створення ASP. NET-проектів у Visual Studio. Файл Default. aspx. cs та обробник Page_Load using using System; System. Collections. Generic; System. Linq; System. Web. UI; System. Web. UI. Web. Controls; Файл генерується автоматично (у MS Visual Studio) для ASP. NET проектів (варіант проекту – ASP. NET Web Application) namespace Web. App_Blanc_3_5 { public partial class _Default : System. Web. UI. Page { protected void Page_Load(object sender, Event. Args e) { } } } ASP. NET - 2010 5
Технологія відокремлення коду (Сode. Behind). (Файли Default. aspx та Default. aspx. cs ”порожнього” проекту) (. NET Framework 3. 5) <%@ Page Language="C#" Auto. Event. Wireup="true" Code. Behind="Default. aspx. cs" Inherits="Web. App_Blanc_3_5. _Default" %> <!DOCTYPE html PUBLIC "-//W 3 C//DTD XHTML 1. 0 Transitional … <html xmlns="http: //www. w 3. org/1999/xhtml"> <head runat="server"> Файл <title></title> Default. aspx </head> <body> <form id="form 1" runat="server"> <div> using System; </div> </form> </body> </html> using using System. Collections. Generic; System. Linq; System. Web. UI; System. Web. UI. Web. Controls; Файл Default. aspx. cs namespace Web. App_Blanc_3_5 { public partial class _Default : System. Web. UI. Page { protected void Page_Load(object sender, Event. Args e) { } } У MS Visual Studio ці два файли } генерується автоматично для проектного ASP. NET - 2010 шаблону ASP. NET Web Application 6
Технологія відокремлення коду (Сode. Behind). (Проект Web. App. Hello) Файл Default. aspx public partial class _Default : System. Web. UI. Page { protected void Page_Load(object sender, Event. Args e) { } protected void Button 1_Click(object sender, Event. Args e) { Label 1. Text = "Hi! This is ASP. NET-project. "; } } Файл ASP. NET - 2010 Default. aspx. cs (фрагмент) 7
Технологія відокремлення коду (Сode. Behind). (Приклад динамічного створення управляючих елементів) protected void Page_Load(object sender, Event. Args e) { if (Check. Box 1. Checked) Файл Default. aspx. cs { (фрагмент) Text. Box tb. Name = new Text. Box(); tb. Name. ID = "tb_Name"; Place. Holder 1. Controls. Add(tb. Name); Required. Field. Validator valid. Name = new Required. Field. Validator(); valid. Name. ID = "rfv_Name"; . . . Place. Holder 1. Controls. Add(valid. Name); }; } Призводить до postback-виклику ASP. NET - 2010 8
До створення ASP. NET-проектів у Visual Studio ASP. NET - 2010 9
Файл Default. aspx (. NET Framework 4. 0) <%@ Page Title="Home Page" Language="C#" Master. Page. File="~/Site. master” Auto. Event. Wireup="true" Використовується Code. Behind="Default. aspx. cs" Inherits="Web. App_Blanc_4. _Default" %> master-сторінка <asp: Content ID="Header. Content" runat="server” Content. Place. Holder. ID="Head. Content"> </asp: Content> <asp: Content ID="Body. Content" runat="server” Content. Place. Holder. ID="Main. Content"> <h 2> Welcome to ASP. NET! </h 2> <p> To learn more about ASP. NET visit <a href="http: //www. asp. net” title="ASP. NET Website">www. asp. net</a>. </p> <p> You can also find <a href= "http: //go. microsoft. com/fwlink/? Link. ID=152368& clcid=0 x 409" title="MSDN ASP. NET Docs">documentation on ASP. NET at MSDN</a>. </p> ASP. NET - 2010 10 </asp: Content>
Візуальне проектування в ASP. NET. Режим Split. Файл Default. aspx порожнього проекту (. NET Framework 3. 5) Split Source Design ASP. NET - 2010 11
Візуальне проектування в ASP. NET. (Проект Web. App. Hello) Візуальне проектування в ASP. NET: – (серверні) управляючі елементи; – обробники подій управляючих елементів. Традиційна техніка! Файл Default. aspx (фрагмент) public partial class _Default : System. Web. UI. Page { protected void Page_Load(object sender, Event. Args e) { } protected void Button 1_Click(object sender, Event. Args e) { Label 1. Text = "Hi! This is ASP. NET-project. "; } } Файл Default. aspx. cs (фрагмент) ASP. NET - 2010 12
Стандартні (серверні) управляючі елементи (контроли) <form id="form 1" runat="server"> <div> <asp: Label ID="Label 1" runat="server"></asp: Label> </div> <asp: Button ID="Button 1" runat="server” onclick="Button 1_Click" Text="Click me, please!" /> </form> public partial class _Default : System. Web. UI. Page { protected void Page_Load(object sender, Event. Args e) { } protected void Button 1_Click(object sender, Event. Args e) { Label 1. Text = "Hi! This is ASP. NET-project. "; } } • XML-теги з монікером asp (<asp: … ); • атрибути runat="server" ; • атрибути ID="Label 1" (для зручного програмного маніпулювання у коді обраної мови, наприклад, C# ). ASP. NET - 2010 14
Проект Web. App. Hello. Збереження стану сторінки (2/2) Кодування Base 64 1 Розкодування byte[] ascii_str = Convert. From. Base 64 String(text. Box 1. Text); label 1. Text = System. Text. Encoding. ASCII. Get. String(ascii_str); Розкодування 2 ASP. NET - 2010 22
Валідатори. Приклад 1 (валідація прізвища) <td>Прізвище</td> <asp: Text. Box ID="txt. SName" runat="server"></asp: Text. Box> <asp: Required. Field. Validator ID="Required. Field. Validator 1" runat="server" Control. To. Validate="txt. SName" Display="Dynamic" Error. Message="Уведіть прізвище"> * </asp: Required. Field. Validator> </td> Візуальне налаштування властивостей валідатора ASP. NET - 2010 25
Валідатори. Приклад 2 (валідація курсу) <td>Курс</td> <asp: Text. Box ID="txt. Course" runat="server"></asp: Text. Box> <asp: Required. Field. Validator ID="Required. Field. Validator 4" runat="server" Error. Message="Уведіть курс" Control. To. Validate="txt. Course" Display="Dynamic"> * </asp: Required. Field. Validator> <asp: Range. Validator ID="Range. Validator 1" runat="server" Control. To. Validate="txt. Course" Display="Dynamic" Error. Message="Некоректне значення курсу" Maximum. Value="6" Minimum. Value="1" Type="Integer"> * </asp: Range. Validator> </td> ASP. NET - 2010 26
Валідатори. Приклад 3 (валідація e-mail) <td> E-mail</td> <asp: Text. Box ID="txt. Email" runat="server">ttp@ukr. net</asp: Text. Box> <asp: Regular. Expression. Validator ID="Regular. Expression. Validator 1" runat="server" Control. To. Validate="txt. Email" Error. Message="Error e-mail" Validation. Expression="w+([-+. ']w+)*@w+([-. ]w+)*. w+([-. ]w+)*" Display="Dynamic"> * </asp: Regular. Expression. Validator> <asp: Required. Field. Validator ID="Required. Field. Validator 3" runat="server" Control. To. Validate="txt. Email" Error. Message="Уведіть e-mail" Display="Dynamic"> * </asp: Required. Field. Validator> ASP. NET - 2010 27
Валідатори. Динамічне створення валідатора protected void Page_Load(object sender, Event. Args e) { if (Check. Box 1. Checked) { Text. Box tb. Name = new Text. Box(); tb. Name. ID = "tb_Name"; Place. Holder 1. Controls. Add(tb. Name); Required. Field. Validator valid. Name = new Required. Field. Validator(); valid. Name. ID = "rfv_Name"; valid. Name. Control. To. Validate = "tb_Name"; valid. Name. Error. Message = "Уведіть ім'я"; valid. Name. Text = "*"; valid. Name. Display=Validator. Display. Dynamic; Place. Holder 1. Controls. Add(valid. Name); }; } ASP. NET - 2010 28
Збереження стану. Використання View. State (2/2) protected void Button 1_Click(object sender, Event. Args e) { if (!Page. Is. Valid) return; string name = string. Empty; Text. Box tb. Name = (Text. Box)Find. Control("tb_Name"); if (tb. Name != null) { name = ", Ім'я=" + tb. Name. Text; }; View. State["email"] = txt. Email. Text; lbl. Out. Text = "Прізвище="+txt. SName. Text + name+", Курс=" + txt. Course. Text + ", E-mail=" + txt. Email. Text; } protected void Button 2_Click(object sender, Event. Args e) { txt. Email. Text = (string)View. State["email"]; } ASP. NET - 2010 30
Використання View. State. Проблеми (1/3) private const int max. Count = 500; protected void Page_Load(object sender, Event. Args e) { for (int i = 0; i < max. Count; i++) { List. Box 1. Items. Add("Варіант " + (i + 1). To. String()); } } ASP. NET - 2010 31
Використання View. State. Проблеми (2/3) <? xml version="1. 0" encoding="utf-8"? > <configuration xmlns= "http: //schemas. microsoft. com/. Net. Configuration/v 2. 0"> <system. web> <trace enabled="true" page. Output="true" /> <compilation debug="true" /> ASP. NET - 2010 </system. web> Файл web. xml </configuration> 32
Відключення View. State (1/2) <asp: List. Box ID="List. Box 1" runat="server" Height="200 px» Width="150 px" Enable. View. State="False" /> protected void Page_Load(object sender, Event. Args e) { for (int i = 0; i < max. Count; i++) { List. Box 1. Items. Add("Варіант " + (i + 1). To. String()); } if (this. Is. Post. Back) { string text = this. Request. Form["List. Box 1"]; List. Box 1. Items. Find. By. Text(text). Selected = true; } else List. Box 1. Selected. Index = 0; } ASP. NET - 2010 34
Відключення View. State (2/2) ASP. NET - 2010 35
Збереження стану. Використання схованих полів (Hidden Fields) HTML-коду (2/2) protected void Page_Load(object sender, Event. Args e) { Умова першого (не postback) if (!this. Is. Post. Back) звернення до сторінки { Begin. Time. Value = System. Date. Time. Now. To. Long. Time. String(); } } protected void Button 1_Click(object sender, Event. Args e) { Label 1. Text = "Початок роботи зі сторінкою: " + Begin. Time. Value; Label 2. Text = "Поточний час: " + System. Date. Time. Now. To. Long. Time. String(); } Зауваження. View. State та сховані поля не забезпечують передачу даних при переходах від однієї сторінки до іншої. ASP. NET - 2010 37
Приклади зчитування даних, що містяться у Cookie if(Request. Cookies["name"] != null) Label. Text = Server. Html. Encode(Request. Cookies["name"]. Value); if(Request. Cookies["name"] != null) { Http. Cookie a. Cookie = Request. Cookies["name"]; Label. Text = Server. Html. Encode(a. Cookie. Value); } Зауваження: – перевірка if(Request. Cookies["name"] != null) убезпечує від переривання; – кодування Html. Encode(a. Cookie. Value) страхує від можливого додавання зловмисниками виконуваного скрипта у Cookie. ASP. NET - 2010 44
Приклад проекту з Cookie (2/2) protected void Button 1_Click(object sender, Event. Args e) { Response. Cookies["Cookie. IT"]. Value = "Value. Cookie. IT"; Response. Cookies["Cookie. IT"]. Expires = Date. Time. Now. Add. Minutes(10); } protected void Button 2_Click(object sender, Event. Args e) { string accepts. Cookies; if (Request. Cookies["Cookie. IT"] == null) accepts. Cookies = "нe "; else { accepts. Cookies = ""; Response. Cookies["Cookie. IT"]. Expires = Date. Time. Now. Add. Days(-1); }; Label 3. Text = "Файли cookie " + accepts. Cookies + "підтримуються браузером"; } ASP. NET - 2010 46
Передача даних між сторінками. Використання рядка запиту (Query String) (2/2) protected void Page_Load(object sender, Event. Args e) { if (!this. Is. Post. Back) { lbl. Time. Text = System. Date. Time. Now. To. Long. Time. String(); } } protected void Button 1_Click(object sender, Event. Args e) { string URL = "Page 2. aspx? Begin. Time="+ Server. Url. Encode(lbl. Time. Text); this. Response. Redirect(URL); } protected void Page_Load(object sender, Event. Args e) { if (this. Request. Query. String["Begin. Time"] != null && !this. Is. Post. Back) Label 1. Text = "Початок роботи з проектом: " + this. Request. Query. String["Begin. Time"]; Label 2. Text = "Поточний час: " + System. Date. Time. Now. To. Long. Time. String(); ASP. NET - 2010 } Page 2. aspx. cs (фрагмент) 48
Збереження стану. Використання Session-контейнера. Приклад Передача Session. Id між клієнтом і сервером: – на основі Cookie (за замовчуванням); – шляхом включення Session. Id в URL (зокрема, у випадку, коли браузер не підтримує Cookie). (2/3) Session. Id складається з ASCII-символів, які можна використовувати в URL. <? xml version="1. 0" encoding="utf-8"? > <configuration xmlns= "http: //schemas. microsoft. com/. Net. Configuration/v 2. 0"> <system. web> <compilation debug="true" /> Деякі можливості роботи із Session: • Session. Add(“Name”, “Value”); <session. State cookieless="true"/> • Session[“Name”]=“Val 2”; </system. web> • Session. Timeout=2; // 2 хвилини </configuration> Файл Web. config • Session. Abandon(); Session. Id ASP. NET - 2010 50
Збереження стану. Використання Session-контейнера. Приклад (3/3) protected void Button 1_Click(object sender, Event. Args e) { this. Session["name"] = Text. Box 1. Text; this. Response. Redirect("Page 1. aspx"); Start. aspx. cs } protected void Page_Load(object sender, Event. Args e) { Label 1. Text = "Name = " + (string)this. Session["name"] + ", Session. ID = " + this. Session. ID; } protected void Button 1_Click(object sender, Event. Args e) { this. Response. Redirect("Page 2. aspx"); } Page 1. aspx. cs ASP. NET - 2010 5151
Збереження стану. Використання Applicationконтейнера. Приклад (2/3) public class Global : System. Web. Http. Application { void Application_Start(object sender, Event. Args e) { this. Application["count 1"] = (int)0; this. Application["count 2"] = (int)0; } void Session_End(object sender, Event. Args e) { this. Application["count 2"] = (int)this. Application["count 2"] - 1; } void Session_Start(object sender, Event. Args e) { this. Application["count 2"] = (int)this. Application["count 2"] + 1; } } Global. aspx. cs ASP. NET - 2010 53
Збереження стану. Використання Applicationконтейнера. Приклад (3/3) protected void Page_Load(object sender, Event. Args e) { this. Application. Lock(); this. Application["count 1"] = (int)this. Application["count 1"] + 1; this. Application. Un. Lock(); Label 1. Text = "Загальна кількість відвідувань сайту - " + (int)this. Application["count 1"]; Label 2. Text = "Зараз відвідувачів - " + (int)this. Application["count 2"]; } App. State. aspx. cs ASP. NET - 2010 54
ASP. NET - 2010 56
ASP. NET - 2010 57
ASP. NET - 2010 58
ASP. NET - 2010 59
ASP. NET - 2010 60
ASP. NET - 2010 61
ASP. NET - 2010 62
- Classic asp to asp.net migration
- Feature flag meaning
- Authentication filters in mvc 5
- Introduction to asp.net
- Asp net core future
- Asp.net execution model
- Crud asp.net c# web forms
- Asp net core future
- Asp.net timeline control
- Request.onreadystatechange
- Asp.net xss bypass
- Asp net load testing
- Custom controls in asp.net
- Asp.net agenda
- 大阪 microsoft asp.net
- Asp.net agenda
- What is aspnet
- Desarrollo de aplicaciones web con asp.net
- Client server architecture in asp net
- Asp.net web api 2
- Asmx soap
- Azure bug bounty
- Reflection in asp net
- 2160711
- Asp.net server controls
- Asp internet
- Asp.net session management
- Net developer roadmap
- Asp.net tutorialspoint
- Asp net session state
- T. trimpe 2010 http //sciencespot.net/
- Https //sciencespot.net answers
- Do while asp
- Asp co to jest
- Fft asp
- Asp 102
- Asp brunei
- Shell finder online
- Negative prefixes
- Jurgen asp
- Asp session object
- Need for madness 3
- Mswc.adrotator
- Php sql injection 방지 함수
- Standar asp untuk entitas nirlaba yang dicabut pada 2019
- Outsourcing asp
- Quiero ser bombera corrigé
- Sylaé connexion
- Inurl:to.asp?card=
- Triade de von wahl
- Asp cordenonese
- Asp-all-route-data
- Asp medical
- Asp syla
- Asp
- Aspint
- Valvule connivente asp
- Apa itu asp
- Nehudlit
- Safersys snapshot
- Asp include
- Signe de rovsing
- Score de blamey