techdays 2013 jari kallonen: what's new webforms 4.5

30
Régis Laurent Director of Operations, Global Knowledge Competencies include: Gold Learning Silver System Management ASP .NET WebForms 4.5 uudet piirteet Jari Kallonen Software Specialist at Tieturi Oy

Upload: tieturi-oy

Post on 19-Jun-2015

287 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: TechDays 2013 Jari Kallonen: What's New WebForms 4.5

Régis Laurent Director of Operations, Global Knowledge Competencies include: Gold Learning Silver System Management

ASP.NET WebForms 4.5 uudet piirteet

Jari Kallonen Software Specialist at Tieturi Oy

Page 2: TechDays 2013 Jari Kallonen: What's New WebForms 4.5

Régis Laurent Director of Operations, Global Knowledge Competencies include: Gold Learning Silver System Management

- Strongly Typed Data Controls

- Model Binding - HTML Encoded

Data-Binding Expressions

- Unobtrusive Validation

- HTML5 tuki - Muuta sälää

Page 3: TechDays 2013 Jari Kallonen: What's New WebForms 4.5

Tyypitetty Data Bindings

<div> <asp:Repeater ID="CustomerRepeater" runat="server" ItemType="Demoilua.Model.Henkilo"> <ItemTemplate> <li> ID:<%# Item.ID %> Nimi:<%# Item.Nimi %> Puhelin:<%# Item.Puhelin %> </li> </ItemTemplate> </asp:Repeater> </div>

Page 4: TechDays 2013 Jari Kallonen: What's New WebForms 4.5

Model Binding – Tiedon valinta

public IEnumerable<Demoilua.Model.Henkilo> GetData() { return Demoilua.Model.HenkiloRepository.HaeKaikki(); }

<div> <asp:Repeater ID="CustomerRepeater" runat="server" ItemType="Demoilua.Model.Henkilo” SelectMethod="GetData"> <ItemTemplate> <li> ID:<%# Item.ID %> Nimi:<%# Item.Nimi %> Puhelin:<%# Item.Puhelin %> </li> </ItemTemplate> </asp:Repeater> </div>

Page 5: TechDays 2013 Jari Kallonen: What's New WebForms 4.5

Value Providers - QueryString

public IQueryable<Customer> GetCustomers( [QueryString]string keyword) { return CustomerRepository.GetByName(keyword); }

Page 6: TechDays 2013 Jari Kallonen: What's New WebForms 4.5

Value Providers - Kontrollit

public IQueryable<Customer> GetCustomers( [Control("customers")]int? id) { if (id.HasValue) return CustomerRepository.GetOne(id); else return CustomerRepository.GetAll(); }

Page 7: TechDays 2013 Jari Kallonen: What's New WebForms 4.5

Value Provider vaihtoehtoja

• Controls • Query string values • View Data • Session State • Cookies • Posted Form data • View State • Custom

Page 8: TechDays 2013 Jari Kallonen: What's New WebForms 4.5

2-suuntainen Binding

<EditItemTemplate> ID:<asp:TextBox ID="IDTextBox" runat="server" Text='<%# BindItem.ID %>' /> LastName:<asp:TextBox ID="NimiTextBox" runat="server" Text='<%# BindItem.Nimi %>' /> Puhelin:<asp:TextBox ID="PuhelinTextBox" runat="server" Text='<%# BindItem.Puhelin %>' /> </EditItemTemplate>

Page 9: TechDays 2013 Jari Kallonen: What's New WebForms 4.5

Demo

Binding, Value Providers

Page 10: TechDays 2013 Jari Kallonen: What's New WebForms 4.5

Markup based validointi

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="nimiTextBox" ErrorMessage="Nimi puuttuu" ForeColor="Red" />

Page 11: TechDays 2013 Jari Kallonen: What's New WebForms 4.5

Unobtrusive (”huomaamaton”) validointi

Pienentää sivun kokoa vähentämällä inline Javacript koodin käyttöä ->Käyttää HTML5 data-* attribuutteja • ValidationSettings:UnobtrusiveValidationMode • Asetus: – Web.Config – Global.asax – Page luokka

Page 12: TechDays 2013 Jari Kallonen: What's New WebForms 4.5

javascript validointi

Page 13: TechDays 2013 Jari Kallonen: What's New WebForms 4.5

Unobtrusive validointi

Edellinen ”Unobstrusive” muodossa

Page 14: TechDays 2013 Jari Kallonen: What's New WebForms 4.5

Data annotaatiot Model luokassa

public class Henkilo { [Key] public int ID { get; set; } [Required] public string Nimi { get; set; } [Range(0, 130)] public int Ika { get; set; } [Phone] public string Puhelin { get; set; } [EmailAddress, StringLength(256)] public string Email { get; set; } }

Page 15: TechDays 2013 Jari Kallonen: What's New WebForms 4.5

Joitain Data Annotaatioita

• CreditCard • Phone • EmailAddress • Range • Compare • Url • FileExtensions • Required • Key • RegularExpression

Page 16: TechDays 2013 Jari Kallonen: What's New WebForms 4.5

Model luokan validointi

public void SaveCustomer(Customer customer) { if (ModelState.IsValid) { using (var db = new Demoilua.Model.ProductsContext()) { db.Customers.Add(customer); db.SaveChanges(); Response.Redirect("~/Customers.aspx"); } } }

Page 17: TechDays 2013 Jari Kallonen: What's New WebForms 4.5

Validointikontrollit

<asp:ValidationSummary runat="server" ShowModelStateErrors="true" ForeColor="Red" HeaderText="Please check the following errors:" /> <asp:ModelErrorMessage ModelStateKey="phone" runat="server" ForeColor="Red" />

Page 18: TechDays 2013 Jari Kallonen: What's New WebForms 4.5

Tulos:

Page 19: TechDays 2013 Jari Kallonen: What's New WebForms 4.5

Demo

Validointi

Page 20: TechDays 2013 Jari Kallonen: What's New WebForms 4.5

Request validointi

• Korvaa tarvittaessa HttpEncoderin • Auttaa suojautumaan cross-site scripting (XSS) ja LDAP injection hyökkäyksiltä • AntiXSS libraryssa – HtmlEncode, HtmlFormUrlEncode,HtmlAttributeEncode – XmlAttributesEncode, XmlEncode – UrlEncode , UrlPathEncode – CssEncode

Page 21: TechDays 2013 Jari Kallonen: What's New WebForms 4.5

4.5 Request validointi

<system.web> … <httpRuntime encoderType="System.Web.Security.AntiXss.AntiXssEncoder" /> </system.web>

Page 22: TechDays 2013 Jari Kallonen: What's New WebForms 4.5

Tuki await/async ja Task pohjaisille pyynnöille

• HTTP Modules EventHandlerTaskAsyncHelper TaskEventHandler • HTTP Handlers HttpTaskAsyncHandler

Page 23: TechDays 2013 Jari Kallonen: What's New WebForms 4.5

Async tuki

• Web.config <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/> • Page directive <%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="ProductDetails.aspx.cs" Inherits="WebFormsLab.ProductDetails" Async="true" %>

Page 24: TechDays 2013 Jari Kallonen: What's New WebForms 4.5

Async Task esimerkki

RegisterAsyncTask(new PageAsyncTask(async (t) => { using (var wc = new WebClient()) { //aikaisemmin wc.DownloadFile await wc.DownloadFileTaskAsync( imageUrl, Server.MapPath(product.ImagePath)); } }));

Page 25: TechDays 2013 Jari Kallonen: What's New WebForms 4.5

HTML5 päivityksiä

• TextBox TextMode – Tukee email, datetime tyyppejä jne. • FileUpload – tuki useammalle upload tiedostolle – Selainriippuvainen • Validointikontrollit tukee HTML5 elementtejä • runat=“server” lisäksi URL osoite –<video runat=“server” src=“~/file.wmv”/>

Page 26: TechDays 2013 Jari Kallonen: What's New WebForms 4.5

ASP.NET Core päivityksiä

• WebSockets Protocol (IIS8) • Javascriptin ja CSS:n pakkaus (Bundling / Minification) • Suorituskyky – Yhteisten komponenttien jako (muistin kulutus) – Multi-core JIT käännös – Garbage Collection – Web sovellusten esilataukset

Page 27: TechDays 2013 Jari Kallonen: What's New WebForms 4.5

Javascriptin ja CSS:n pakkauksen määrittely

using System.Web.Optimization; //… public class BundleConfig { public static void RegisterBundles(BundleCollection bundles) { bundles.Add(new ScriptBundle("~/bundles/jquery").Include( "~/Scripts/jquery-{version}.js")); bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include( "~/Scripts/jquery-ui-{version}.js")); bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include( "~/Scripts/jquery.unobtrusive*", "~/Scripts/jquery.validate*")); bundles.Add(new ScriptBundle("~/bundles/WebFormsJs").Include( "~/Scripts/WebForms/WebForms.js", "~/Scripts/WebForms/WebUIValidation.js", "~/Scripts/WebForms/MenuStandards.js", "~/Scripts/WebForms/Focus.js", "~/Scripts/WebForms/GridView.js“); } }

Page 28: TechDays 2013 Jari Kallonen: What's New WebForms 4.5

Visual Studio 2012 parannuksia

HTML Editor Smart Tasks, loppu/alku elementin päivitys HTML 5 snippets, parempi Intellisense, … http://www.asp.net/vnext/overview/whitepapers/whats-new#_Toc303354490 JavaScript Editor Code outlining, Go to Definition, … http://www.asp.net/vnext/overview/whitepapers/whats-new#_Toc303354500 CSS Editor Color Picker, CSS 3 support, custom region (/*#region Menu */ … /*#endregion */ http://www.asp.net/vnext/overview/whitepapers/whats-new#_Toc303354508

Page 29: TechDays 2013 Jari Kallonen: What's New WebForms 4.5

Yhteenveto

Model pohjainen binding Validointi Laajentunut Html 5 tuki Async/Await ja Task –pohjaiset toiminnot Suorituskykyä Coreen

Page 30: TechDays 2013 Jari Kallonen: What's New WebForms 4.5

© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentations. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Kiitos ja kumarrus [email protected]