2. Client requests
the web page
5. Browser processes
HTML and displays
page
CLIENT
9
Dynamic web page
• Dynamic Web sites provide its visitors to modify the content of
the web page based on their input.
• They utilize databases and other mechanisms that enable to
– identify their visitors
– present them with customized greeting messages
– restructure the content according to user input etc..
• Examples:
– Online shopping stores,
– search engines
– email
– chat, community portals etc.
10
Dynamic web page
• Dynamic Web sites make use of “server-side
technology”.
• Server-side technologies add an extra layer to the
static web page that enables the Web Server to
generate HTML on the fly.
• The web server will first
– interpret the server-side code present in web
pages,
– generate the appropriate HTML and then
– send the response to the web browser.
11
How Are Dynamic Web Pages Served?
3. Web Server collects the contents
(code + HTML) of the web page
WEB SERVER and parses the contents to
produce HTML.
2. The Web Server
searches for the
requested page 4. The HTML stream is
sent back to the
requesting browser
CLIENT
12
Introduction to ASP.NET
Introduction to ASP.NET
ASP.NET is part of the Microsoft .NET framework
ASP.NET is an effective and flexible technology for
creating interactive and dynamic web
pages.
It is a convergence of two major Microsoft technologies:
– Active Server Pages (ASP)
• Active Server Pages is Microsoft’s server side scripting
technology for building dynamic web pages.
– .NET Framework
• The .NET Framework is a suite of technologies designed by
Microsoft where program development takes place.
14
Introduction to ASP.NET
It is built on .NET Common Language Runtime
ASP.NET :
Provides better user authentication
Has better language support.
Has a large set of new controls (web controls)
Uses compiled code, which increases the performance of the
applications
It is programmable using any of the .NET languages
(VB.NET, C#, VJ# virtual J# etc).
The ASP.NET pages are saved with the .aspx
extension. 15
Working of an ASP.NET Application
To execute an ASP.NET file, the
following steps are followed: ASP.NET
1. A web browser sends a Script
request for an ASP.NET file to Engine
the web server by using a
URL.
ASP.Net avant …
4
ASP.NET MVC
Master Page
Control Control
UI
Control Page
Control Presentation Logic
Business Logic
Control Control Data Access
Control Control
5
ASP.NET MVC
7
ASP.NET MVC
Positionnement
Framework .NET
ASP.NET
Présentation
Dynamic
WebForms MVC Ajax WebPages
Data
8
ASP.NET MVC
9
ASP.NET MVC
What is ASP.NET?
ASP.NET WebForms
◼ HttpContext ◼ Postback
◼ HttpRequest ◼ ViewState
◼ HttpResponse
◼ HttpRuntime
◼ HttpUtility ASPX
◼ IHttpHandler ◼ MasterPages
◼ General Templating
10
What is the ASP.NET MVC
ASP.NET MVC
Framework?
ASP.NET Mvc
◼ HttpApplication ◼ Routes
◼ HttpContext ◼ Controllers
◼ HttpRequest ◼ ViewData
◼ HttpResponse ◼ Filters
◼ HttpRuntime
◼ HttpUtility ASPX
◼ IHttpHandler ◼ MasterPages
◼ General Templating
11
Architecture de ASP.NET MVC
ASP.NET MVC
Le Pattern MVC
http://www.dotnetcurry.com/aspnet-mvc/922/aspnet-mvc-pattern-tutorial-fundamentals
13
ASP.NET MVC
Le Pattern MVC
ASP.NET MVC
14
ASP.NET MVC
◼ ASP.NET MVC1
◼ Released on Mar 13, 2009
◼ Runs on .Net 3.5 and with Visual Studio 2008 & Visual Studio 2008 SP1
◼ MVC Pattern architecture with ASPX Engine
◼ Html Helpers/Ajax helpers/Routing/Unit Testing
◼ ASP.NET MVC2
◼ Released on Mar 10, 2010
◼ Runs on .Net 3.5, 4.0 and with Visual Studio 2008 & 2010
◼ Strongly typed HTML helpers means lambda expression based Html Helpers
◼ Templated Helpers/Support for Data Annotations Attribute
◼ Client-side validation/UI helpers with automatic scaffolding & customizable templates
◼ Attribute-based model validation on both client and server
◼ Overriding the HTTP Method Verb including GET, PUT, POST, and DELETE
◼ Areas for partitioning a large applications into modules
◼ ASP.NET MVC3
◼ Released on Jan 13, 2011
◼ Runs on .Net 4.0 and with Visual Studio 2010
◼ The Razor view engine
◼ Improved Support for Data Annotations/Dependency Resolver
◼ Partial-page output caching/Global Action Filters/Better JavaScript support with unobtrusive
JavaScript, jQuery Validation, and JSON binding
16
ASP.NET MVC
◼ ASP.NET MVC4
◼ Released on Aug 15, 2012
◼ Runs on .Net 4.0, 4.5 and with Visual Studio 2010SP1 & Visual Studio 2012
◼ ASP.NET Web API
◼ Enhancements to default project templates
◼ Mobile project template using jQuery Mobile
◼ Display Modes
◼ Task support for Asynchronous Controllers
◼ Bundling and minification
◼ Support for the Windows Azure SDK
◼ ASP.NET MVC5
◼ Released on 17 October 2013
◼ Runs on .Net 4.5, 4.5.1 and with Visual Studio 2013
◼ One Asp.Net
◼ Asp.Net Identity
◼ ASP.NET Scaffolding
◼ Authentication filters - run prior to authorization filters in the ASP.NET MVC pipeline
◼ Bootstrap in the MVC template
◼ ASP.NET Web API2
17
Mise en œuvre de ASP.NET
MVC
ASP.NET MVC
Default Structure
View templates
Configuration file
19
19
ASP.NET MVC
The controller !
20
ASP.NET MVC
21
ASP.NET MVC
Result
22
ASP.NET MVC
◼ System.Web.Routing.RouteTable.Routes
◼ In Global.asax in the Application_Start() there is
RoutesConfig.RegisterRoutes(RouteTable.Routes);
23
ASP.NET MVC
Routing Examples
http://localhost/Products/ById/3
◼ Controller: Products
◼ Action: ById
◼ Id: 3
24
24
ASP.NET MVC
Route Constraints
25
25
ASP.NET MVC
Controllers
26
ASP.NET MVC
Actions
27
27
ASP.NET MVC
Action Results
EmptyResult No response
FileContentResult Return the contents of a file File
FilePathResult
FileStreamResult
HttpUnauthorizedResult Returns an HTTP 403 status
28
28
ASP.NET MVC
Action Parameters
◼ ASP.NET MVC maps the data from the HTTP request to action
parameters in few ways:
◼ Routing engine can pass parameters to actions
◼ http://localhost/Users/NikolayIT
29
29
ASP.NET MVC
Action Selectors
◼ ActionName(string name)
◼ AcceptVerbs
◼ HttpPost
◼ HttpGet
◼ HttpDelete
◼ HttpOptions
◼ …
◼ NonAction
◼ RequireHttps
◼ ChildActionOnly – Only for Html.Action()
30
30
ASP.NET MVC
Action Filters
◼ Apply pre- and post-processing logic. Some requirements cut across logical
boundaries are called cross-cutting concerns. Examples include:
◼ Authorization
◼ Logging
◼ Caching
Name Description
OutputCache Cache the output of a controller
ValidateInput(false) Turn off request validation and allow dangerous
input (html tags)
31
31
Le moteur de vue Razor
ASP.NET MVC
Views
34
34
ASP.NET MVC
Razor
35
35
ASP.NET MVC
36
36
ASP.NET MVC
37
37
ASP.NET MVC
How it works?
ByUsername.cshtml HTML
Output
Generated
Template Data
Output
UsersController.cs
UserModel.cs
38
38
ASP.NET MVC
Razor Syntax
<p>
Current time is: !!!
Not HTML encoded value:
</p>
39
39
ASP.NET MVC
<div class="products-list">
<b> , </b>
</div>
40
40
ASP.NET MVC
<p>
This is the sign that separates email names from domains: @@<br />
And this is how smart Razor is: spam_me@gmail.com
</p>
41
41
ASP.NET MVC
<p>
Current rating(0-10): @Model.Rating / 10.0 @* 6 / 10.0 *@
Current rating(0-1): @(Model.Rating / 10.0) @* 0.6 *@
spam_me@Model.Rating @* spam_me@Model.Rating *@
spam_me@(Model.Rating) @* spam_me6 *@
</p>
<p> </p>
42
42
ASP.NET MVC
Layout
43
43
ASP.NET MVC
View Helpers
46
46
ASP.NET MVC
HTML Helpers
50
ASP.NET MVC
51