Vous êtes sur la page 1sur 50

.NET Framework 4.

5
1

Introduction to ASP.NET 4.5

Email: kiemhh@fpt.com.vn

Agenda
2

The ASP.NET Core Runtime and Framework ASP.NET WebForms


Strongly Typed Data Controls
Model Binding HTML Encoded Data-Binding Expressions Unobtrusive Validation HTML5 Updates

Microsoft Web Platform


3

This is the Web Platform for Professional Developers. It combines a rich and powerful web application framework with a supporting cast of tools, servers, technologies and applications for creating, designing, developing and delivering web solutions.

Web Platform Installer

ASP.NET 4.5 Web Forms

ASP.NET MVC 4

ADO.NET Entity Framework


SQL Server 2012 IIS 8.0

Visual Studio 2012

Ajax Control Toolkit & jQuery

Visual Studio 2012


4

IIS Express by default for new Web Sites


ASP.NET Development Server still included for backward

compatibility

LocalDB default database server ASP.NET Project Templates


Unify all templates over Web Forms, MVC and Web Pages Build in mobile support

Visual Studio 2012

HTML Editor Enhancements


5

Automatic Event Handler generation

Smart Tasks

Visual Studio 2012

HTML Editor Enhancements


6

Extract To User Control Highlight the a piece of code, right-click and select Extract to User Control in menu

Visual Studio 2012

HTML Editor Enhancements


7

HTML5 snippets

Visual Studio 2012

HTML Editor Enhancements


8

Element Matching
When we rename an HTML element (change a div tag to be a header tag), the corresponding opening or closing tag also changes in real time.

Smart indent

Visual Studio 2012

HTML Editor Enhancements


9

IntelliSense for code nuggets in attributes

Visual Studio 2012

HTML Enhancements
10

ASP.NET Web Forms defaults to XHTML5 doctype


Use DocType button in toolbar

Support for new HTML5 form controls


Enhanched TextMode property on TextBox control

Visual Studio 2012

CSS Editor Enhancements


11

CSS Editor Hierarchical Indentation CSS Editor Snippets CSS Color Picker Better Cross Browser support

Visual Studio 2012

CSS Editor Enhancements


12

CSS Editor Hierarchical Indentation

Visual Studio 2012

CSS Editor Enhancements


13

CSS Color Picker


IntelliSense for color-related attributes consisted of a dropdown list of named color values

Visual Studio 2012

CSS Editor Enhancements


14

CSS Editor Snippets


Snippets in the CSS editor make it easier and faster to create cross-browser styles

Visual Studio 2012

Javascript Editor Enhancements


15

Support for ECMAScript 5 and HTML5 DOM

Auto-reducing Statement Completion List in IntelliSense


IntelliSense show function signature

Support for
Go To Definition Brace Matching Outlining

Visual Studio 2012

Page Inspector
16

Page Inspector is a tool that renders a web page (HTML, Web Forms, ASP.NET MVC, or Web Pages) in the Visual Studio IDE and lets you examine both the

source code and the resulting output


Page Inspector lets you determine which server-side

code has produced the HTML markup that is rendered


to the browser

Visual Studio 2012

Page Inspector
17

ASP.NET Runtime
18

Script Libraries as NuGet Packages Web Optimization Async Universal Providers Request Validation Data Annotations Miscellaneous Support for WebSockets Protocol

ASP.NET Runtime

Script Libraries as NuGet Packages


19

Today
Project templates ship with script libraries jQuery jQuery UI Libraries are updated and template is out of date Where do I go to get latest version?

Visual Studio 11
Script libraries are included as NuGet packages Updated automatically via NuGet Package Manager

ASP.NET Runtime

Web Optimization
20

Modern HTML pages can include lots of CSS and JavaScript references
Each one is retrieved with a separate HTTP request Not automatically minified

ASP.NET 4.5 can bundle and minify your JavaScript and CSS

ASP.NET Runtime

JavaScript Bundling And Minification


21

Default JavaScript bundling behavior Take all JavaScript files in a certain folder Sort them alphabetically Then reordered so that know libraries are loaded first (jQuery, Dojo, MooTools) The default bundle is called js Include the following script link to load the default bundle in your page

ASP.NET Runtime

CSS Bundling And Minification


22

Default CSS bundling behavior


Take all CSS files in a certain folder
Sort them alphabetically Then reorganized so that reset.css and normalize.css come before any other CSS file

The default bundle is called css Include the following script link to load the default bundle in your page

ASP.NET Runtime

Bundling And Minification


23

You can register your own bundles in Global.asax for custom processing

Referencing your custom bundle

ASP.NET Runtime

Async
24

Support for the new Await keyword in ASP.NET


Ensure that the Task return value from await

can be wired up to an IAsyncResult


Supported: Handlers HttpModule MVC 4

ASP.NET Runtime

Asynchronous HttpModule
25

Suppose to perform asynchronous work within a method that returns a Task object

ASP.NET Runtime

Asynchronous HttpHandler
26

The traditional approach to writing asynchronous handlers in ASP.NET is to implement the IHttpAsyncHandler interface

ASP.NET Runtime

Universal Providers
27

Membership, Profile, Role, Session providers only work against certain version of SQL Server

Universal Providers are built on top of Entity Framework


and work against any database supported by Entity Framework SQL Server, Azure SQL, SQL Compact and many more Released as a NuGet soon and included in v.Next

ASP.NET Runtime

Request Validation
28

History:
.NET 2.0
<%@ ValidateRequest=false %> disabled validation for the entire page
.NET 4

Request validation was moved earlier in the pipeline allowing protection of Modules. To turn it off for a page you had to revert to the 2.0 mode losing the new protection

Web Pages 1 / MVC 3


Provide new unvalidated collections of form, query string, cookie collections allowing granular access

ASP.NET Runtime

Request Validation
29

ASP.NET 4.5 enhancements


Disable request validation on a single control ValidateRequestMode attribute on ASP.NET Control Lazy Request Validation Validation only done when value is accessed explicitly i.e.: Request.Form[<key>] In web.config Set ValidateRequestMode on control to Disabled To access the un-validated request manually i.e.: Request.Unvalidated.Form[<key>] Be careful with this

ASP.NET 4.5
30

Data Annotations
Compare CreditCard EmailAddress FileExtension Phone Url DataType CreditCard PostalCode Upload

Miscellaneous
Startup performance & working set improvements Incremental file upload Allow uploads > 2GB Anti-XSS encoders ASP.NET admin modules And more

ASP.NET 4.5

HTML 5
31

SP1: <input type=date runat=server /> vNext: <asp:TextBox runat=server TextMode=Date />

Text Multiline Password Color Date DateTime

DateTimeLocal Email Month Number Range Search

Phone Time Url Week

ASP.NET 4.5

Project Templates
32

Script libraries included as NuGet packages


Updatable

HTML 5
Dynamically updates to device size Modernizer library Templates use HTML 5 that gracefully falls back on older browsers

ASP.NET 4.5

Strongly Typed Data Controls


33

Strongly Typed Data Expressions Intellisense Compile time not run time errors

ASP.NET 4.5

Model Binding
34

Model binding extends data binding in ASP.NET Web

Forms controls to work with code-focused data access


It incorporates concepts from the ObjectDataSource control and from model binding in ASP.NET MVC
Selecting data Value providers Filtering by values from a control

ASP.NET 4.5

Model Binding Selecting Data


35

To configure a data control to use model binding to

select data,we set the control's SelectMethod property


to the name of a method in the page's code. The data control calls the method at the appropriate time in the page life cycle and automatically binds the returned data.

There's no need to explicitly call the DataBind method.

ASP.NET 4.5

Model Binding Selecting Data


36

ASP.NET 4.5

Model Binding Value Providers


37

By default, the parameter name is used as the key to

find a value in the value provider collection.


for example :

ASP.NET 4.5

Model Binding Filter By Values


38

ASP.NET 4.5

Model Binding Filter By Values


39

ASP.NET 4.5

HTML encoded Data-Binding Expressions


40

We can now HTML-encode the result of data-binding

expressions. Add a colon (:) to the end of the <%#


prefix that marks the data-binding expression:

ASP.NET 4.5

Ubobtrusive Javascript
41

In ASP.NET 4.0 Validators generated inline JavaScript for


client-side validation Increases page size

HTML source is cluttered


Unobtrusive Validation uses HTML5 data attributes and jQuery Enabled by default via web.config or in code

ASP.NET 4.5

Ubobtrusive Javascript
42

Cleaner page markup


Supports pluggable client validation libraries jQueryValidate is default implementation Markup:

<asp:TextBox runat="server" ID="txtFirstName" /> <asp:RequiredFieldValidator ID="rfvFirstName" runat="server" ControlToValidate="txtFirstName" ErrorMessage="Please enter a value for First Name" />

ASP.NET 4.5

Ubobtrusive Javascript
43

<script src="Scripts/jQuery-1.8.2.js" type="text/javascript"></script> <script src="Scripts/jQuery.validate.js" type="text/javascript"></script> <script src="Scripts/jQuery.validate.unobtrusive.js" type="text/javascript"></script> <input name="txtFirstName" type="text" id="txtFirstName" data-val="true" data-val-focusonerror="false" data-val-required="Please enter a value for First Name" /> <span id="rfvFirstName" class="field-validation-valid" data-valmsg-for="txtFirstName" data-valmsg-replace="true"> </span>

ASP.NET 4.5

Web Socket Protocol


44

WebSockets protocol is a standards-based network protocol that defines how to establish secure, real-time bidirectional communications between a client and a server over HTTP. The WebSockets protocol is supported by any client (not just browsers), and mobile operating systems.

WebSockets protocol makes it much easier to create longrunning data transfers between a client and a server

ASP.NET 4.5

Web Socket Protocol


45

ASP.NET 4.5 and IIS 8 include low-level WebSockets support,

enabling ASP.NET developers to use managed APIs for


asynchronously reading and writing both string and binary data on a WebSockets object.

ASP.NET 4.5

Web Socket Protocol


46

ASP.NET MVC 4

Overview Release Details Supports Visual Studio 2010 Ship in box with Visual Studio 11 Feature Overview Mobile Support and Mobile Template Single Page Applications WCF Web API

ASP.NET MVC 4 & WCF WEB API

ASP.NET MVC
ASP.NET Routing Model binding Validation Filters Link generation Testability Dependency resolver

WCF Web API


Modern HTTP programming model Task-based async Content negotiation Server-side query composition Test client, help page Self-host

Web Links to Additional Resources


49

http://www.nuget.org
http://aka.ms/mbl-tech http://aka.ms/mbl-tech/devprev http://aka.ms/mbl-tech/html5 http://www.asp.net/vnext

ASP.NET 4.5
50

Thank You Q&A

Vous aimerez peut-être aussi