SlideShare a Scribd company logo
ASP.NET: Building Web Application… in the right way
ASP.NET a brief history
• 2001 – first release
• 2009 – ASP.NET MVC
• 2012 – ASP.NET Web API
• 2013 – OWIN and SignalR
• 2015 – ASP.NET 5 (RC1)
MVC pattern
notifies
Controller
Model
View
interacts
with
modifies
modifies
listens /
gets data from
MVC web style
Webpageinteracts
with
Controller
Model
View
selects a
passes a model to
acts on
gets data fromproduces
invokes
ASP.NET MVC
• A new presentation option for ASP.NET
• Simpler way to program ASP.NET
• Easily testable and TDD friendly
• More control over your <html/>
• More control over your URLs
• Supports existing ASP.NET features
• Removes: viewstate and postback needs
Routing
Webpageinteracts
with
Controller
Model
View
selects a
passes a model to
acts on
gets data fromproduces
invokes
Routing - example
public class OrdersController : Controller
{
public ActionResult Index()
{
}
public ActionResult Details(int id)
{
}
}
http://www.yoursite.com/Orders/Details/1
Routing - example
http://www.yoursite.com/Orders/Details/1
public class OrdersController : Controller
{
public ActionResult Index()
{
}
public ActionResult Details(int id)
{
}
}
Routing - example
http://www.yoursite.com/Orders/Details/1
public class OrdersController : Controller
{
public ActionResult Index()
{
}
public ActionResult Details(int id)
{
}
}
Routing – configuration
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home",
action = "Index", id = UrlParameter.Optional });
}
Routing – configuration
routes.MapMvcAttributeRoutes();
//
public class OrdersController : Controller
{
[Route("Orders/{id}/Items")]
public ActionResult OrderItems(int id)
{
}
}
http://www.yoursite.com/Orders/1/Items
Controller
Webpageinteracts
with
Controller
Model
View
selects a
passes a model to
acts on
gets data fromproduces
invokes
Controller
public class OrdersController : Controller
{
public ActionResult Details(int? id)
{
Order order = db.Orders.Find(id);
if (order == null)
return HttpNotFound();
return View(order);
}
}
View("MyWonderfulOrderView", order);
Controller – routing and HTTP methods
public class OrdersController : Controller
{
// GET: Orders/Edit/5
public ActionResult Edit(int? id)
{
}
// POST: Orders/Edit/5
[HttpPost]
public ActionResult Edit(Order order)
{
}
}
Model
Webpageinteracts
with
Controller
Model
View
selects a
passes a model to
acts on
gets data fromproduces
invokes
Model
• View Model or Business Model
• Validation attributes, for example:
• Required
• EmailAddress
• StringLength
• View-related attributes, e.g. Display
public class LoginViewModel
{
[Required]
[Display(Name = "Email address")]
[EmailAddress]
public string Email { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[Display(Name = "Remember me")]
public bool RememberMe { get; set; }
}
View
Webpageinteracts
with
Controller
Model
View
selects a
passes a model to
acts on
gets data fromproduces
invokes
View
• Related to controllers/actions by naming convetion
• Several View Engine. Standard: Razor, WebFormViewEngine
• Support layouts and partial views
• Can use strongly-typed model (e.g. Order) or dynamic one (ViewBag)
• @Html helper methods (e.g. @Html.TextBoxFor)
• @Html methods can be extended
ActionResult
• ActionResult is the base class for action’s return types
• Available results:
• ViewResult - Renders a specifed view to the response stream
• RedirectResult - Performs an HTTP redirection to a specifed URL
• RedirectToRouteResult - Performs an HTTP redirection to a URL that is determined by
the routing engine, based on given route data
• JsonResult - Serializes a given ViewData object to JSON format
• ContentResult - Writes content to the response stream without requiring a view
• FileContentResult - Returns a file to the client
• and more
Model binder
• Transform values from client to .NET class instances or primitive types
• Retrieves values from HTML form variables, POSTed variables, query string
and routing parameters
• DefaultModelBinder is the default binder
• Binding can be customized, for specific types at application level or at action’s
parameter level
Filters
• Enable Aspect Oriented Programming (AOP)
• Different types for different needs:
• Authorization filters – IAuthorizationFilter
• Action filters – IActionFilter
• Result filters – IResultFilter
• Exception filters – IExceptionFilter
• Filters can be applied to a single action or a whole controller
Q&A
Q&A
ASP.NET Web API
• Formerly part of WCF framework
• 2012 – First release
• 2013 – Release of Web API 2
• First class framework for HTTP-based services
• Foundamental for creating RESTful services
• Self-hosted
• Different stacks, same concepts – System.Web.Mvc  System.Web.Http
ASP.NET Web API cf. MVC
• Similar route patterns declarations
• Request/method name matching by HTTP verbs
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
ASP.NET Web API cf. MVC
GET http://www.yoursite.com/api/Orders/5
public class OrdersController : ApiController
{
IQueryable<Order> GetOrders() { … }
IHttpActionResult GetOrder(int id) { … }
IHttpActionResult PutOrder(int id, Order order) { … }
IHttpActionResult PostOrder(Order order) { … }
IHttpActionResult DeleteOrder(int id) { … }
}
ASP.NET Web API cf. MVC
• No views or ActionResult just data or IHttpActionResult
• Data are serialized in JSON or other format (e.g. XML)
• Controllers inherit from ApiController
• No more HttpContext.Current
• View filters
ASP.NET Web API - OData
“An open protocol to allow the creation and consumption of queryable and
interoperable RESTful APIs in a simple and standard way”
EnableQueryAttribute
Implements out of the box most of the OData query system: filters, pagination,
projection, etc.
Let’s go to code
Let’s go to code
Q&A
Q&A
What’s next? ASP.NET 5
ASP.NET 5 – .NET Core
• Totally modular
• Faster development cycle
• Seamless transition from on-premises to cloud
• Choose your editor and tools
• Open-source
• Cross-platform
• Fast
ASP.NET 5 cf. ASP.NET 4.X
• No more Web Forms and Web API only MVC
• One ring stack to rule them all, i.e. no more double coding
• Tag helpers – cleaner HTML views
• Project and configuration files in JSON
• Server side and client side packages completelly decoupled
• much more 
thank you for your attention
stay tuned for next workshops
Andrea Vallotti, ph.D
andrea.vallotti@commitsoftware.it

More Related Content

What's hot (20)

PPTX
Building dynamic applications with the share point client object model
Eric Shupps
 
PPTX
Angular js for Beginnners
Santosh Kumar Kar
 
PPT
RichControl in Asp.net
Bhumivaghasiya
 
PPTX
Standard List Controllers
Mohammed Safwat Abu Kwaik
 
PDF
JavaLand 2014 - Ankor.io Presentation
manolitto
 
PDF
Introduction to ajax
Nir Elbaz
 
PPTX
AngularJS 1.x - your first application (problems and solutions)
Igor Talevski
 
PPT
Asp.net server controls
Raed Aldahdooh
 
PPTX
Ankor Presentation @ JavaOne San Francisco September 2014
manolitto
 
PPTX
Asp.net mvc 6 with sql server 2014
Fahim Faysal Kabir
 
PPTX
Presentation on asp.net controls
Reshi Unen
 
PPTX
Sitecore MVC (User Group Conference, May 23rd 2014)
Ruud van Falier
 
PPTX
Asp.Net MVC
Sudheesh Valathil
 
PDF
Tech Talk Live on Share Extensibility
Alfresco Software
 
PPTX
SFDC UI - Introduction to Visualforce
Sujit Kumar
 
PPTX
Getting a Quick Start with Visualforce
Mohammed Safwat Abu Kwaik
 
PPTX
Standard control in asp.net
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Advance java session 15
Smita B Kumar
 
Building dynamic applications with the share point client object model
Eric Shupps
 
Angular js for Beginnners
Santosh Kumar Kar
 
RichControl in Asp.net
Bhumivaghasiya
 
Standard List Controllers
Mohammed Safwat Abu Kwaik
 
JavaLand 2014 - Ankor.io Presentation
manolitto
 
Introduction to ajax
Nir Elbaz
 
AngularJS 1.x - your first application (problems and solutions)
Igor Talevski
 
Asp.net server controls
Raed Aldahdooh
 
Ankor Presentation @ JavaOne San Francisco September 2014
manolitto
 
Asp.net mvc 6 with sql server 2014
Fahim Faysal Kabir
 
Presentation on asp.net controls
Reshi Unen
 
Sitecore MVC (User Group Conference, May 23rd 2014)
Ruud van Falier
 
Asp.Net MVC
Sudheesh Valathil
 
Tech Talk Live on Share Extensibility
Alfresco Software
 
SFDC UI - Introduction to Visualforce
Sujit Kumar
 
Getting a Quick Start with Visualforce
Mohammed Safwat Abu Kwaik
 
Advance java session 15
Smita B Kumar
 

Viewers also liked (20)

PDF
02 Introduction to Javascript
crgwbr
 
PDF
Javascript
atozknowledge .com
 
PDF
Building Applications Using Ajax
s_pradeep
 
PPTX
HTML 5
Karthik Madhavan
 
PPT
Html5(2)
Carol Maughan
 
PPTX
INFT132 093 07 Document Object Model
Michael Rees
 
PPT
introduction to the document object model- Dom chapter5
FLYMAN TECHNOLOGY LIMITED
 
PPTX
Dom(document object model)
Partnered Health
 
PPT
3.jsp tutorial
shiva404
 
PPTX
Document object model
Amit kumar
 
PPT
Document Object Model
yht4ever
 
PPTX
An Introduction to the DOM
Mindy McAdams
 
PPTX
Introduction To Building Enterprise Web Application With Spring Mvc
Abdelmonaim Remani
 
PPTX
Document object model(dom)
rahul kundu
 
PPT
Document Object Model
chomas kandar
 
PPT
Document Object Model
chomas kandar
 
PPTX
Jsp (java server page)
Chitrank Dixit
 
PPTX
Java/Servlet/JSP/JDBC
FAKHRUN NISHA
 
PDF
Building Web Application Using Spring Framework
Edureka!
 
PPT
Open Source Technology
priyadharshini murugan
 
02 Introduction to Javascript
crgwbr
 
Javascript
atozknowledge .com
 
Building Applications Using Ajax
s_pradeep
 
Html5(2)
Carol Maughan
 
INFT132 093 07 Document Object Model
Michael Rees
 
introduction to the document object model- Dom chapter5
FLYMAN TECHNOLOGY LIMITED
 
Dom(document object model)
Partnered Health
 
3.jsp tutorial
shiva404
 
Document object model
Amit kumar
 
Document Object Model
yht4ever
 
An Introduction to the DOM
Mindy McAdams
 
Introduction To Building Enterprise Web Application With Spring Mvc
Abdelmonaim Remani
 
Document object model(dom)
rahul kundu
 
Document Object Model
chomas kandar
 
Document Object Model
chomas kandar
 
Jsp (java server page)
Chitrank Dixit
 
Java/Servlet/JSP/JDBC
FAKHRUN NISHA
 
Building Web Application Using Spring Framework
Edureka!
 
Open Source Technology
priyadharshini murugan
 
Ad

Similar to ASP.NET - Building Web Application..in the right way! (20)

PPTX
Que hay de nuevo en Visual Studio 2013 y ASP.NET 5.1
Rodolfo Finochietti
 
PPTX
MVC 4
Vasilios Kuznos
 
PDF
ASP.NET MVC - Whats The Big Deal
Venketash (Pat) Ramadass
 
PPTX
ZZ BC#8 Hello ASP.NET MVC 4 (dks)
Chalermpon Areepong
 
PPTX
Asp.net With mvc handson
Prashant Kumar
 
PDF
ASP.NET Web API Interview Questions By Scholarhat
Scholarhat
 
PDF
ASP NET Web API 2 Building a REST Service from Start to Finish 2nd Edition Ja...
prienmance8p
 
PPTX
Web api
udaiappa
 
PDF
MVC Interview Questions PDF By ScholarHat
Scholarhat
 
PDF
ASP.NET MVC 2.0
Buu Nguyen
 
PPTX
ASP.NET Presentation
Rasel Khan
 
PPTX
MVC 6 - the new unified Web programming model
Alex Thissen
 
PPTX
Web API or WCF - An Architectural Comparison
Adnan Masood
 
PPTX
Developing Web Sites and Services using Visual Studio 2013
Microsoft Visual Studio
 
PPTX
A Minimalist’s Attempt at Building a Distributed Application
David Hoerster
 
PPTX
Skillwise - Advanced web application development
Skillwise Group
 
PPTX
Learning ASP.NET 5 and MVC 6
Ido Flatow
 
PDF
Difference between asp.net web api and asp.net mvc
Umar Ali
 
PPTX
ASP.NET Mvc 4 web api
Tiago Knoch
 
PDF
Asp.Net MVC Framework Design Pattern
maddinapudi
 
Que hay de nuevo en Visual Studio 2013 y ASP.NET 5.1
Rodolfo Finochietti
 
ASP.NET MVC - Whats The Big Deal
Venketash (Pat) Ramadass
 
ZZ BC#8 Hello ASP.NET MVC 4 (dks)
Chalermpon Areepong
 
Asp.net With mvc handson
Prashant Kumar
 
ASP.NET Web API Interview Questions By Scholarhat
Scholarhat
 
ASP NET Web API 2 Building a REST Service from Start to Finish 2nd Edition Ja...
prienmance8p
 
Web api
udaiappa
 
MVC Interview Questions PDF By ScholarHat
Scholarhat
 
ASP.NET MVC 2.0
Buu Nguyen
 
ASP.NET Presentation
Rasel Khan
 
MVC 6 - the new unified Web programming model
Alex Thissen
 
Web API or WCF - An Architectural Comparison
Adnan Masood
 
Developing Web Sites and Services using Visual Studio 2013
Microsoft Visual Studio
 
A Minimalist’s Attempt at Building a Distributed Application
David Hoerster
 
Skillwise - Advanced web application development
Skillwise Group
 
Learning ASP.NET 5 and MVC 6
Ido Flatow
 
Difference between asp.net web api and asp.net mvc
Umar Ali
 
ASP.NET Mvc 4 web api
Tiago Knoch
 
Asp.Net MVC Framework Design Pattern
maddinapudi
 
Ad

More from Commit Software Sh.p.k. (18)

PPTX
Building real time app by using asp.Net Core
Commit Software Sh.p.k.
 
PDF
Let's talk about GraphQL
Commit Software Sh.p.k.
 
PPTX
Arduino and raspberry pi for daily solutions
Commit Software Sh.p.k.
 
DOCX
Lets build a neural network
Commit Software Sh.p.k.
 
PPTX
Hacking a WordPress theme by its child
Commit Software Sh.p.k.
 
PPTX
Magento 2 : development and features
Commit Software Sh.p.k.
 
PPTX
Building modern applications in the cloud
Commit Software Sh.p.k.
 
PPTX
Design patterns: Understand the patterns and design your own
Commit Software Sh.p.k.
 
PPTX
Blockchain - a simple implementation
Commit Software Sh.p.k.
 
PPTX
Laravel and angular
Commit Software Sh.p.k.
 
PPTX
Drupal 7: More than a simple CMS
Commit Software Sh.p.k.
 
PPTX
Intro to Hybrid Mobile Development && Ionic
Commit Software Sh.p.k.
 
PDF
Wordpress development 101
Commit Software Sh.p.k.
 
PPTX
Ruby on rails
Commit Software Sh.p.k.
 
ODP
Cloud Computing
Commit Software Sh.p.k.
 
PDF
Web apps in Python
Commit Software Sh.p.k.
 
PPTX
Laravel - The PHP framework for web artisans
Commit Software Sh.p.k.
 
PDF
Automation using RaspberryPi and Arduino
Commit Software Sh.p.k.
 
Building real time app by using asp.Net Core
Commit Software Sh.p.k.
 
Let's talk about GraphQL
Commit Software Sh.p.k.
 
Arduino and raspberry pi for daily solutions
Commit Software Sh.p.k.
 
Lets build a neural network
Commit Software Sh.p.k.
 
Hacking a WordPress theme by its child
Commit Software Sh.p.k.
 
Magento 2 : development and features
Commit Software Sh.p.k.
 
Building modern applications in the cloud
Commit Software Sh.p.k.
 
Design patterns: Understand the patterns and design your own
Commit Software Sh.p.k.
 
Blockchain - a simple implementation
Commit Software Sh.p.k.
 
Laravel and angular
Commit Software Sh.p.k.
 
Drupal 7: More than a simple CMS
Commit Software Sh.p.k.
 
Intro to Hybrid Mobile Development && Ionic
Commit Software Sh.p.k.
 
Wordpress development 101
Commit Software Sh.p.k.
 
Ruby on rails
Commit Software Sh.p.k.
 
Cloud Computing
Commit Software Sh.p.k.
 
Web apps in Python
Commit Software Sh.p.k.
 
Laravel - The PHP framework for web artisans
Commit Software Sh.p.k.
 
Automation using RaspberryPi and Arduino
Commit Software Sh.p.k.
 

Recently uploaded (20)

PPTX
Introduction to Design of Machine Elements
PradeepKumarS27
 
PPT
PPT2_Metal formingMECHANICALENGINEEIRNG .ppt
Praveen Kumar
 
PPTX
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
PPTX
artificial intelligence applications in Geomatics
NawrasShatnawi1
 
PPTX
Green Building & Energy Conservation ppt
Sagar Sarangi
 
PDF
Zilliz Cloud Demo for performance and scale
Zilliz
 
PPTX
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
PPTX
Introduction to Neural Networks and Perceptron Learning Algorithm.pptx
Kayalvizhi A
 
DOC
MRRS Strength and Durability of Concrete
CivilMythili
 
DOCX
8th International Conference on Electrical Engineering (ELEN 2025)
elelijjournal653
 
PPTX
Arduino Based Gas Leakage Detector Project
CircuitDigest
 
DOCX
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
PDF
Design Thinking basics for Engineers.pdf
CMR University
 
PPTX
265587293-NFPA 101 Life safety code-PPT-1.pptx
chandermwason
 
PDF
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
PPTX
Heart Bleed Bug - A case study (Course: Cryptography and Network Security)
Adri Jovin
 
PPTX
Depth First Search Algorithm in 🧠 DFS in Artificial Intelligence (AI)
rafeeqshaik212002
 
PDF
Unified_Cloud_Comm_Presentation anil singh ppt
anilsingh298751
 
PPTX
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
PDF
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 
Introduction to Design of Machine Elements
PradeepKumarS27
 
PPT2_Metal formingMECHANICALENGINEEIRNG .ppt
Praveen Kumar
 
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
artificial intelligence applications in Geomatics
NawrasShatnawi1
 
Green Building & Energy Conservation ppt
Sagar Sarangi
 
Zilliz Cloud Demo for performance and scale
Zilliz
 
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
Introduction to Neural Networks and Perceptron Learning Algorithm.pptx
Kayalvizhi A
 
MRRS Strength and Durability of Concrete
CivilMythili
 
8th International Conference on Electrical Engineering (ELEN 2025)
elelijjournal653
 
Arduino Based Gas Leakage Detector Project
CircuitDigest
 
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
Design Thinking basics for Engineers.pdf
CMR University
 
265587293-NFPA 101 Life safety code-PPT-1.pptx
chandermwason
 
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
Heart Bleed Bug - A case study (Course: Cryptography and Network Security)
Adri Jovin
 
Depth First Search Algorithm in 🧠 DFS in Artificial Intelligence (AI)
rafeeqshaik212002
 
Unified_Cloud_Comm_Presentation anil singh ppt
anilsingh298751
 
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 

ASP.NET - Building Web Application..in the right way!

  • 1. ASP.NET: Building Web Application… in the right way
  • 2. ASP.NET a brief history • 2001 – first release • 2009 – ASP.NET MVC • 2012 – ASP.NET Web API • 2013 – OWIN and SignalR • 2015 – ASP.NET 5 (RC1)
  • 4. MVC web style Webpageinteracts with Controller Model View selects a passes a model to acts on gets data fromproduces invokes
  • 5. ASP.NET MVC • A new presentation option for ASP.NET • Simpler way to program ASP.NET • Easily testable and TDD friendly • More control over your <html/> • More control over your URLs • Supports existing ASP.NET features • Removes: viewstate and postback needs
  • 6. Routing Webpageinteracts with Controller Model View selects a passes a model to acts on gets data fromproduces invokes
  • 7. Routing - example public class OrdersController : Controller { public ActionResult Index() { } public ActionResult Details(int id) { } } http://www.yoursite.com/Orders/Details/1
  • 8. Routing - example http://www.yoursite.com/Orders/Details/1 public class OrdersController : Controller { public ActionResult Index() { } public ActionResult Details(int id) { } }
  • 9. Routing - example http://www.yoursite.com/Orders/Details/1 public class OrdersController : Controller { public ActionResult Index() { } public ActionResult Details(int id) { } }
  • 10. Routing – configuration public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }); }
  • 11. Routing – configuration routes.MapMvcAttributeRoutes(); // public class OrdersController : Controller { [Route("Orders/{id}/Items")] public ActionResult OrderItems(int id) { } } http://www.yoursite.com/Orders/1/Items
  • 12. Controller Webpageinteracts with Controller Model View selects a passes a model to acts on gets data fromproduces invokes
  • 13. Controller public class OrdersController : Controller { public ActionResult Details(int? id) { Order order = db.Orders.Find(id); if (order == null) return HttpNotFound(); return View(order); } } View("MyWonderfulOrderView", order);
  • 14. Controller – routing and HTTP methods public class OrdersController : Controller { // GET: Orders/Edit/5 public ActionResult Edit(int? id) { } // POST: Orders/Edit/5 [HttpPost] public ActionResult Edit(Order order) { } }
  • 15. Model Webpageinteracts with Controller Model View selects a passes a model to acts on gets data fromproduces invokes
  • 16. Model • View Model or Business Model • Validation attributes, for example: • Required • EmailAddress • StringLength • View-related attributes, e.g. Display public class LoginViewModel { [Required] [Display(Name = "Email address")] [EmailAddress] public string Email { get; set; } [Required] [DataType(DataType.Password)] [Display(Name = "Password")] public string Password { get; set; } [Display(Name = "Remember me")] public bool RememberMe { get; set; } }
  • 17. View Webpageinteracts with Controller Model View selects a passes a model to acts on gets data fromproduces invokes
  • 18. View • Related to controllers/actions by naming convetion • Several View Engine. Standard: Razor, WebFormViewEngine • Support layouts and partial views • Can use strongly-typed model (e.g. Order) or dynamic one (ViewBag) • @Html helper methods (e.g. @Html.TextBoxFor) • @Html methods can be extended
  • 19. ActionResult • ActionResult is the base class for action’s return types • Available results: • ViewResult - Renders a specifed view to the response stream • RedirectResult - Performs an HTTP redirection to a specifed URL • RedirectToRouteResult - Performs an HTTP redirection to a URL that is determined by the routing engine, based on given route data • JsonResult - Serializes a given ViewData object to JSON format • ContentResult - Writes content to the response stream without requiring a view • FileContentResult - Returns a file to the client • and more
  • 20. Model binder • Transform values from client to .NET class instances or primitive types • Retrieves values from HTML form variables, POSTed variables, query string and routing parameters • DefaultModelBinder is the default binder • Binding can be customized, for specific types at application level or at action’s parameter level
  • 21. Filters • Enable Aspect Oriented Programming (AOP) • Different types for different needs: • Authorization filters – IAuthorizationFilter • Action filters – IActionFilter • Result filters – IResultFilter • Exception filters – IExceptionFilter • Filters can be applied to a single action or a whole controller
  • 23. ASP.NET Web API • Formerly part of WCF framework • 2012 – First release • 2013 – Release of Web API 2 • First class framework for HTTP-based services • Foundamental for creating RESTful services • Self-hosted • Different stacks, same concepts – System.Web.Mvc  System.Web.Http
  • 24. ASP.NET Web API cf. MVC • Similar route patterns declarations • Request/method name matching by HTTP verbs config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional }
  • 25. ASP.NET Web API cf. MVC GET http://www.yoursite.com/api/Orders/5 public class OrdersController : ApiController { IQueryable<Order> GetOrders() { … } IHttpActionResult GetOrder(int id) { … } IHttpActionResult PutOrder(int id, Order order) { … } IHttpActionResult PostOrder(Order order) { … } IHttpActionResult DeleteOrder(int id) { … } }
  • 26. ASP.NET Web API cf. MVC • No views or ActionResult just data or IHttpActionResult • Data are serialized in JSON or other format (e.g. XML) • Controllers inherit from ApiController • No more HttpContext.Current • View filters
  • 27. ASP.NET Web API - OData “An open protocol to allow the creation and consumption of queryable and interoperable RESTful APIs in a simple and standard way” EnableQueryAttribute Implements out of the box most of the OData query system: filters, pagination, projection, etc.
  • 28. Let’s go to code Let’s go to code
  • 31. ASP.NET 5 – .NET Core • Totally modular • Faster development cycle • Seamless transition from on-premises to cloud • Choose your editor and tools • Open-source • Cross-platform • Fast
  • 32. ASP.NET 5 cf. ASP.NET 4.X • No more Web Forms and Web API only MVC • One ring stack to rule them all, i.e. no more double coding • Tag helpers – cleaner HTML views • Project and configuration files in JSON • Server side and client side packages completelly decoupled • much more 
  • 33. thank you for your attention stay tuned for next workshops Andrea Vallotti, ph.D [email protected]

Editor's Notes

  • #4: 1970s – First «implemetation» 1988 – Described as a pattern several interpretations mainly used in GUI clear division between domain objects that model our perception of the real world, and presentation objects that are the GUI elements we see on the screen one model – multiple views (even command line)
  • #7: Given an URL, the routing engine is in charge of: invoking the correct controller and method (called action); parsing the parameters contained in it.
  • #8: By naming convetion routing engine will look for a controller (i.e. a class) named OrdersController; Then it will look for an action (i.e. a method) named Details; Routing engine will also try to parse the URL looking for parameter which should be passed to
  • #9: By naming convetion routing engine will look for a controller (i.e. a class) named OrdersController; Then it will look for an action (i.e. a method) named Details; Routing engine will also try to parse the URL looking for parameter which should be passed to
  • #10: By naming convetion routing engine will look for a controller (i.e. a class) named OrdersController; Then it will look for an action (i.e. a method) named Details; Routing engine will also try to parse the URL looking for parameter which should be passed to
  • #11: Standard way of defining routing convention/pattern; Several definitions can be added; Priority based on order; Segment defaults or optional.
  • #12: Highly customizable Integrated with the "standard approach";
  • #14: What is a controller: it is a class which derives from Controller class; it exposes public methods which return ActionResult or subclasses of the latter (see in detail later); these methods are called actions; Inside the action usually: it gets a model and acts on it; then select a View (by default the view has the same name of the action) and pass to it the model Other ways to pass data to the View: ViewBag: dynamic, property of the controller Stateless As a rule of thumb actions name must be different even if signatures differ otherwise routing is not able to choose the correct method for a given URL
  • #15: You can have more more methods with the same name by specifing the HTTP method: AcceptVerbsAttribute HttpDeleteAttribute HttpGetAttribute HttpHeadAttribute HttpOptionsAttribute HttpPatchAttribute HttpPostAttribute HttpPutAttribute
  • #16: The Model of MVC is intended to be a "View Model" (example default UserLoginModel) However also the Business Model can be used You can use validation attribute to let MVC validate the user input
  • #17: The Model of MVC is intended to be a "View Model" (example default LoginViewModel) However also the Business Model can be used You can use validation attribute to let MVC validate the user input You can also use attribute to help rendering the view System.ComponentModel.DataAnnotations
  • #18: Helper, Bundle, etc.
  • #19: By default all the views are placed in Views/<controller name>/<action name>.cshtml Each project can use its preferred View Engine There are also third-party View Engine which allow to use RoR or Django syntax Layouts are like master pages in old ASP.NET Different layouts can be used for different sections of the application (using Layout property) Strongly-typed using @model directive, dynamic using ViewBag ViewBag can be used by the View (even in strongly-typed) to pass information to the layout and partial views Html helper methods can be used to render standard html elements Helper, Bundle, etc.
  • #20: Usually action’s return type is ActionResult but you can be more specific using a derived class
  • #21: DefaultModelBinder creates an empty instance and fills it with values received from client The default binder can be changed using ModelBinders.Binders.DefaultBinder We will see a customization example during the demo
  • #22: Filters are executed in the order listed Authorization filters are used to implement authentication and authorization for controller actions You can use an action filter, for instance, to modify the view data that a controller action returns. Result filters - you might want to modify a view result right before the view is rendered to the browser. You can use an exception filter to handle errors raised by either your controller actions or controller action results. You also can use exception filters to log errors. System.Web.Mvc.FilterAttribute base class
  • #24: WCF – Windows Communication Foundation is mainly aimed to SOAP-based services ASP.NET MVC relies on IIS (standard or express) while ASP.NET Web API can be self-hosted
  • #25: Routing - same declaration style, different classes By default action are matched by HTTP verbs not segment of URL
  • #26: GET http://www.yoursite.com/api/Orders/5  OrdersController.GetOrder(5)
  • #27: Data are serialized in JSON or XML based on Accept header of HTTP request Web API was design to work without a web server (i.e. IIS) and with async framework therefore you should never use HttpContext.Current especially when self-hosted Web API is responsible to pass the correct context to each operation Action, Authorization and Exception filters are still available
  • #28: Basically OData is a way to standardize REST services, e.g. by defining how to filter It is «simply» an action filter which works with an IQueryable
  • #31: .NET Core 5: is the version of .NET that runs on Mac, Windows and Linux; brings features via packages  framework much smaller; ASP.NET 5 runs both on .NET Framework 4.6 and .NET Core;
  • #32: Totally modular – cause all the library (such as MVC, file, etc.) have been stripped from the core  you have to download them with NuGet Faster development cycle – simply modify the code and refresh your page, the code will be automatically compiled Seamless transition – the application runs with its own framework and libraries therefore you do not need to install «special» stuff on the server Editor and tools – Visual Studio, Visual Studio Code on all platforms but through OmniaSharp also emacs, sublime, etc. are supported. Yeoman generator!!! Cross-platform – Kestrel is a standalone web server based on libuv (the same as Node.JS), Fast  benchmarks show that ASP.NET 5 is faster than Node.JS 
  • #33: ASP.NET 5  only MVC which contains both old MVC and Web API One stack  one Controller base class, one routing configuration, model binding, etc. All controllers can have actions which return ActionResult or data System.Web.* does not exist anymore we have the package Microsoft.AspNet.Mvc Tag helpers  just like angular directive, allows to write more HTML and take advantage of intellisense for CSS and HTML JSON files  no more XML, JSON is easier to understand and widely used Server/client side  NuGet for the server and Bower for the client
  • #34: Vi rigrazio per l’attenzione e spero di essere riuscito a sintetizzare un argomento che richiede molti approfondimenti. Qui trovate i miei contatti e sono a disposizione al desk per un veloce incontro per rispondere a tutte le vostre domande. Grazie ancora e buon forum a tutti.