SlideShare une entreprise Scribd logo
1  sur  50
Asp.Net MVC A new “pluggable” web framework Stefano Paluello stefano.paluello@pastesoft.com http://stefanopaluello.wordpress.com Twitter: @palutz
MVC and Asp.Net The Model, the View and the Controller (looks like “The Good, the Bad and the Ugly” ) HtmlHelper and PartialView Routing Filters TDD with Asp.Net MVC Agenda
MVC and Asp.Net From WebForm to MVC
Asp.Net Asp.Net was introduced in 2002 (.Net 1.0) It was a big improvement from the “spaghetti code” that came with Asp classic It introduced a new programming model, based on Events, Server-side Controls and “stateful” Form (Session, Cache, ViewState): the RAD/VB-like development model for the web. It allowed a lot of developers to deal with the Web, also if they have limited or no skills at all in HTML and JavaScript. Build with productivity in mind
Windows Form and Web Form models Server Reaction Code Action Server HttpRequest Serialize/ Deserialize Webform state Code HttpResponse
Events and State management are not HTTP concepts (you need a quite big structure to manage them) The page life cycle, with all the events handler, can become really complicated and also delicate (easy to break) You have low control over the HTML code generated The complex Unique ID values for the server-side controls don’t fit well with Javascript functions There is a fake feeling of separation of concerns with the Asp.Net’s code behind Automated test could be challenging. That’s cool… But
Web standards HTTP CSS Javascript REST (Representational State Transfer), represents an application in terms of resources, instead of SOAP, the Asp.Net web service base technology Agile and TDD The Web development today is
So… Welcome, Asp.Net MVC WEB
Asp.Net MVC “tenets” Be extensible, maintainable and flexible Be testable Have a tight control over HTML and HTTP Use convention over configuration DRY: don’t repeat yourself Separation of concerns
The MVC pattern
Separation of concerns Separation of concerns comes naturally with MVC Controller knows how to handle a request, that a View exist, and how to use the Model (no more) Model doesn’t know anything about a View View doesn’t know there is a Controller
Asp.Net > Asp.Net MVC Based on the .Net platform (quite straightforward  ) Master page Forms authentication Membership and Role providers Profiles Internationalization Cache Asp.Net MVC is built on (the best part of) Asp.Net
Asp.Net and Asp.Net MVC run-time stack
Demo First Asp.NetMVC application
Asp.Net MVC The structure of the project
Asp.Net MVC projects have some top-level (and core) directories that you don’t need to setup in the config: Controllers, where you put the classes that handle the request Models, where you put the classes that deal with data Views, where you put the UI template files Scripts, where you put Javascript library files and scripts (.js) Content, where you put CSS and image files, and so on App_Data, where you put data files Convention over configuration
Models, Controllers and Views
The Models Classes that represent your application data Contain all the business, validation, and data acccess logic required by your application Three different kind of Model:  data being posted on the Controller data being worked on in the View domain-specific entities from you business tier You can create your own Data Model leveraging the most recommend data access technologies The representation of our data
An actual Data Model using Entity Framework 4.0
ViewModel Pattern Additional layer to abstract the data for the Views from our business tier Can leverage the strongly typed View template features The Controller has to know how to translate from the business tier Entity to the ViewModel one Enable type safety, compile-time checking and Intellisense Useful specially in same complex scenarios Create a class tailored on our specific View scenarios
publicActionResultCustomer(int id) { ViewData[“Customer”] = MyRepository.GetCustomerById(id); ViewData[“Orders”] = MyRepository.GetOrderforCustomer(id); return View(); } publicclassCustomerOrderMV { Customer CustomerData {get; set;} Order CustomerOrders{ get; set;} } publicActionResult Customer(int id) { CustomerOrderMVcustOrd = MyRepository.GetCustomerOrdersById(id); ViewData.Model = custOrd; return View(); } Model vs.ViewModel
Validation Validation and business rule logic are the keys for any application that work with data Schema validation comes quite free if you use OR/Ms Validation and Business Rule logic can be quite easy too using the Asp.Net MVC 2 Data Annotations validation attributes (actually these attributes were introduced as a part of the Asp.Net Dynamic Data) Adding Validation Logic to the Models
[MetadataType(typeof(Blog_Validation))] publicpartialclassBlog { } [Bind(Exclude = "IdBlog")] publicclassBlog_Validation {     [Required(ErrorMessage= "Title required")] [StringLength(50, ErrorMessage = "…")] [DisplayName("Blog Title")]     publicString Title { get; set; } [Required(ErrorMessage = "Blogger required")] [StringLength(50, ErrorMessage = “…")] publicString Blogger { get; set; }ù … } Data Annotations validation How to add validation to the Model through Metadata
Demo Asp.Net MVC Models
The controllers are responsible for responding to the user request Have to implement at least the IController interface, but better if you use the ControllerBaseor the Controller abstract classes (with more API and resources, like the ControllerContext and the ViewData, to build your own Controller) The Controllers
using System; usingSystem.Web.Routing; namespaceSystem.Web.Mvc { // Summary:Defines the methods that are required for a controller. publicinterfaceIController     { // Summary: Executes the specified request context. // Parameters: //   requestContext:The request context. void Execute(RequestContextrequestContext);     } } usingSystem.Web; usingSystem.Web.Mvc; publicclassSteoController : IController { publicvoid Execute(System.Web.Routing.RequestContextrequestContext)     { HttpResponseBase response = requestContext.HttpContext.Response; response.Write("<h1>Hello MVC World!</h1>");     } } My own Controller
publicinterfaceIHttpHandler { voidProcessRequest(HttpContext context); boolIsReusable { get; } } publicinterfaceIController { voidExecute(RequestContextrequestContext); } They look quite similar, aren’t they? The two methods respond to a request and write back the output to a response The Page class, the default base class for ASPX pages in Asp.Net, implements the IHttpHandler. This reminds me something…
The Action Methods All the public methods of a Controller class become Action methods, which are callable through an HTTP request Actually, only the public methods according to the defined Routes can be called
The ActionResult Actions, as Controller’s methods, have to respond to user input, but they don’t have to manage how to display the output The pattern for the Actions is to do their own work and then return an object that derives from the abstract base class ActionResult ActionResultadhere to the “Command pattern”, in which commands are methods that you want the framework to perform in your behalf
The ActionResult publicabstract class ActionResult { public abstract voidExecuteResult(ControllerContext context); } publicActionResultList() { ViewData.Model= // get data from a repository returnView(); }
ActionResult types EmptyResult ContentResult JsonResult RedirectResult RedirectToRouteResult ViewResult PartialViewResult FileResult FilePathResult FileContentResult FileStreamResult JavaScriptResult Asp.Net MVC has several types to help handle the response
Demo Asp.Net MVC Controllers
The Views are responsible for providing the User Interface (UI) to the user The View receive a reference to a Model and it transforms the data in a format ready to be presented The Views
Asp.Net MVC’s View Handles the ViewDataDictionary and translate it into HTML code It’s an Asp.Net Page, deriving from ViewPage (System.Web.Mvc.ViewPage) which itself derives from Page (System.Web.UI.Page) By default it doesn’t include the “runat=server”, that you can add by yourself manually, if you want to use some server controls in your View (better to use only the “view-only” controls) Can take advantage of the Master Page, building Views on top of the Asp.Net Page infrastructure
Asp.Net MVC Views’ syntax You will use <%: %> syntax (often referred to as “code nuggets”) to execute code within the View template. There are two main ways you will see this used: Code enclosed within <% %> will be executed Code enclosed within <%: %> will be executed, and the result will be output to the page
Demo Views, Strongly Typed View, specify a View
Html Helpers Html.Encode Html.TextBox Html.ActionLink, RouteLink Html.BeginForm Html.Hidden Html.DropDownList Html.ListBox Html.Password Html.RadioButton Html.Partial, RenderPartial Html.Action, RenderAction Html.TextArea Html.ValidationMessage Html.ValidationSummary Methods shipped with Asp.Net MVC that help to deal with the HTML code. MVC2 introduced also the strongly typed Helpers, that allow to use Model properties using a Lambda expression instead of a simple string
Partial View Asp.Net MVC allow to define partial view templates that can be used to encapsulate view rendering logic once, and then reuse it across an application (help to DRY-up your code) The partial View has a .ascx extension and you can use like a HTML control
The default Asp.Net MVC project just provide you a simple Partial View: the LogOnUserControl.ascx <%@ControlLanguage="C#"Inherits="System.Web.Mvc.ViewUserControl" %> <% if (Request.IsAuthenticated) { %>         Welcome <b><%:Page.User.Identity.Name %></b>!         [ <%:Html.ActionLink("Log Off", "LogOff", "Account") %> ] <%     } else { %>          [ <%:Html.ActionLink("Log On", "LogOn", "Account") %> ] <%     } %> Partial View Example A simple example out of the box
Ajax You can use the most popular libraries:  Microsoft Asp.Net Ajax jQuery Can help to partial render a complex page (fit well with Partial View) Each Ajax routine will use a dedicated Action on a Controller With Asp.Net Ajax you can use the Ajax Helpers that come with Asp.Net MVC: Ajax.BeginForm AjaxOptions IsAjaxRequest … It’s not really Asp.Net MVC but can really help you to boost your MVC application
Routing Routing in Asp.Net MVC are used to:  Match incoming requests and maps them to a Controller action Construct an outgoing URLs that correspond to Contrller action How Asp.Net MVC manages the URL
Routing vs URL Rewriting They are both useful approaches in creating separation between the URL and the code that handles the URL, in a SEO (Search Engine Optimization) way URL rewriting is a page centric view of URLs (eg: /products/redshoes.aspx rewritten as /products/display.aspx?productid=010) Routing is a resource-centric (not only a page) view of URLs. You can look at Routing as a bidirectional URL rewriting
publicstaticvoidRegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new{ controller = "Home", action = "Index", id = UrlParameter.Optional} // Parameter defaults ); }     protectedvoidApplication_Start() { AreaRegistration.RegisterAllAreas(); RegisterRoutes(RouteTable.Routes); } } Defining Routes The default one…
Route URL patterns
StopRoutingHandler and IgnoreRoute You can use it when you don’t want to route some particular URLs. Useful when you want to integrate an Asp.Net MVC application with some Asp.Net pages.
Filters Filters are declarative attribute based means of providing cross-cutting behavior  Out of the box action filters provided by Asp.Net MVC: Authorize: to secure the Controller or a Controller Action HandleError: the action will handle the exceptions OutputCache: provide output caching to for the action methods
Demo A simple Filter (Session Expire)
TDD with Asp.Net MVC Asp.Net MVC was made with TDD in mind, but you can use also without it (if you want… ) A framework designed with TDD in mind from the first step You can use your favorite Test Framework With MVC you can test the also your UI behavior (!)
Demo TDD with Asp.Net MVC
Let’s start the Open Session:Asp.Net vs. Asp.Net MVC

Contenu connexe

Tendances

Introduction to Spring MVC
Introduction to Spring MVCIntroduction to Spring MVC
Introduction to Spring MVCRichard Paul
 
Angular - Chapter 1 - Introduction
 Angular - Chapter 1 - Introduction Angular - Chapter 1 - Introduction
Angular - Chapter 1 - IntroductionWebStackAcademy
 
Web sockets in Angular
Web sockets in AngularWeb sockets in Angular
Web sockets in AngularYakov Fain
 
Play with Angular JS
Play with Angular JSPlay with Angular JS
Play with Angular JSKnoldus Inc.
 
Beginning AngularJS
Beginning AngularJSBeginning AngularJS
Beginning AngularJSTroy Miles
 
3-TIER ARCHITECTURE IN ASP.NET MVC
3-TIER ARCHITECTURE IN ASP.NET MVC3-TIER ARCHITECTURE IN ASP.NET MVC
3-TIER ARCHITECTURE IN ASP.NET MVCMohd Manzoor Ahmed
 
Comparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAsComparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAsJennifer Estrada
 
10 practices that every developer needs to start right now
10 practices that every developer needs to start right now10 practices that every developer needs to start right now
10 practices that every developer needs to start right nowCaleb Jenkins
 
AngularJS Beginner Day One
AngularJS Beginner Day OneAngularJS Beginner Day One
AngularJS Beginner Day OneTroy Miles
 
Spring MVC Architecture Tutorial
Spring MVC Architecture TutorialSpring MVC Architecture Tutorial
Spring MVC Architecture TutorialJava Success Point
 
ASP.NET AJAX with Visual Studio 2008
ASP.NET AJAX with Visual Studio 2008ASP.NET AJAX with Visual Studio 2008
ASP.NET AJAX with Visual Studio 2008Caleb Jenkins
 
Angular View Encapsulation
Angular View EncapsulationAngular View Encapsulation
Angular View EncapsulationJennifer Estrada
 
Web Performance & Latest in React
Web Performance & Latest in ReactWeb Performance & Latest in React
Web Performance & Latest in ReactTalentica Software
 

Tendances (20)

Introduction to Spring MVC
Introduction to Spring MVCIntroduction to Spring MVC
Introduction to Spring MVC
 
Angular - Chapter 1 - Introduction
 Angular - Chapter 1 - Introduction Angular - Chapter 1 - Introduction
Angular - Chapter 1 - Introduction
 
Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
 
React JS .NET
React JS .NETReact JS .NET
React JS .NET
 
Web sockets in Angular
Web sockets in AngularWeb sockets in Angular
Web sockets in Angular
 
Play with Angular JS
Play with Angular JSPlay with Angular JS
Play with Angular JS
 
Beginning AngularJS
Beginning AngularJSBeginning AngularJS
Beginning AngularJS
 
Asp.net mvc
Asp.net mvcAsp.net mvc
Asp.net mvc
 
3-TIER ARCHITECTURE IN ASP.NET MVC
3-TIER ARCHITECTURE IN ASP.NET MVC3-TIER ARCHITECTURE IN ASP.NET MVC
3-TIER ARCHITECTURE IN ASP.NET MVC
 
Comparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAsComparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAs
 
10 practices that every developer needs to start right now
10 practices that every developer needs to start right now10 practices that every developer needs to start right now
10 practices that every developer needs to start right now
 
Testing Angular
Testing AngularTesting Angular
Testing Angular
 
AngularJS Beginner Day One
AngularJS Beginner Day OneAngularJS Beginner Day One
AngularJS Beginner Day One
 
Spring MVC Architecture Tutorial
Spring MVC Architecture TutorialSpring MVC Architecture Tutorial
Spring MVC Architecture Tutorial
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
ASP.NET AJAX with Visual Studio 2008
ASP.NET AJAX with Visual Studio 2008ASP.NET AJAX with Visual Studio 2008
ASP.NET AJAX with Visual Studio 2008
 
Angular 4
Angular 4Angular 4
Angular 4
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
 
Angular View Encapsulation
Angular View EncapsulationAngular View Encapsulation
Angular View Encapsulation
 
Web Performance & Latest in React
Web Performance & Latest in ReactWeb Performance & Latest in React
Web Performance & Latest in React
 

En vedette

Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVCKhaled Musaied
 
RESTful apps and services with ASP.NET MVC
RESTful apps and services with ASP.NET MVCRESTful apps and services with ASP.NET MVC
RESTful apps and services with ASP.NET MVCbnoyle
 
TDD with Visual Studio 2010
TDD with Visual Studio 2010TDD with Visual Studio 2010
TDD with Visual Studio 2010Stefano Paluello
 
Learning ASP.NET 5 and MVC 6
Learning ASP.NET 5 and MVC 6Learning ASP.NET 5 and MVC 6
Learning ASP.NET 5 and MVC 6Ido Flatow
 
Real scenario: moving a legacy app to the Cloud
Real scenario: moving a legacy app to the CloudReal scenario: moving a legacy app to the Cloud
Real scenario: moving a legacy app to the CloudStefano Paluello
 
Getting Started with ASP.NET MVC
Getting Started with ASP.NET MVCGetting Started with ASP.NET MVC
Getting Started with ASP.NET MVCshobokshi
 
ASP.NET MVC Best Practices malisa ncube
ASP.NET MVC Best Practices   malisa ncubeASP.NET MVC Best Practices   malisa ncube
ASP.NET MVC Best Practices malisa ncubeMalisa Ncube
 
Quoi de neuf dans ASP.NET MVC 4
Quoi de neuf dans ASP.NET MVC 4Quoi de neuf dans ASP.NET MVC 4
Quoi de neuf dans ASP.NET MVC 4Microsoft
 
ASP.NET MVC 5 et Web API 2
ASP.NET MVC 5 et Web API 2ASP.NET MVC 5 et Web API 2
ASP.NET MVC 5 et Web API 2Microsoft
 
ASP.NET MVC 6
ASP.NET MVC 6ASP.NET MVC 6
ASP.NET MVC 6Microsoft
 
70 533 - Module 01 - Introduction to Azure
70 533 - Module 01 - Introduction to Azure70 533 - Module 01 - Introduction to Azure
70 533 - Module 01 - Introduction to AzureGeorges-Emmanuel TOPE
 
Ebook 70 533 implementing microsoft infrastructure solution
Ebook 70 533 implementing microsoft infrastructure solutionEbook 70 533 implementing microsoft infrastructure solution
Ebook 70 533 implementing microsoft infrastructure solutionMahesh Dahal
 
Top 9 c#.net interview questions answers
Top 9 c#.net interview questions answersTop 9 c#.net interview questions answers
Top 9 c#.net interview questions answersJobinterviews
 
Dotnet Basics Presentation
Dotnet Basics PresentationDotnet Basics Presentation
Dotnet Basics PresentationSudhakar Sharma
 

En vedette (19)

Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
RESTful apps and services with ASP.NET MVC
RESTful apps and services with ASP.NET MVCRESTful apps and services with ASP.NET MVC
RESTful apps and services with ASP.NET MVC
 
TDD with Visual Studio 2010
TDD with Visual Studio 2010TDD with Visual Studio 2010
TDD with Visual Studio 2010
 
Windows Azure Overview
Windows Azure OverviewWindows Azure Overview
Windows Azure Overview
 
Entity Framework 4
Entity Framework 4Entity Framework 4
Entity Framework 4
 
Learning ASP.NET 5 and MVC 6
Learning ASP.NET 5 and MVC 6Learning ASP.NET 5 and MVC 6
Learning ASP.NET 5 and MVC 6
 
Real scenario: moving a legacy app to the Cloud
Real scenario: moving a legacy app to the CloudReal scenario: moving a legacy app to the Cloud
Real scenario: moving a legacy app to the Cloud
 
Getting Started with ASP.NET MVC
Getting Started with ASP.NET MVCGetting Started with ASP.NET MVC
Getting Started with ASP.NET MVC
 
ASP.NET MVC Best Practices malisa ncube
ASP.NET MVC Best Practices   malisa ncubeASP.NET MVC Best Practices   malisa ncube
ASP.NET MVC Best Practices malisa ncube
 
Quoi de neuf dans ASP.NET MVC 4
Quoi de neuf dans ASP.NET MVC 4Quoi de neuf dans ASP.NET MVC 4
Quoi de neuf dans ASP.NET MVC 4
 
ASP.NET MVC 5 et Web API 2
ASP.NET MVC 5 et Web API 2ASP.NET MVC 5 et Web API 2
ASP.NET MVC 5 et Web API 2
 
ASP.NET MVC 6
ASP.NET MVC 6ASP.NET MVC 6
ASP.NET MVC 6
 
70 533 - Module 01 - Introduction to Azure
70 533 - Module 01 - Introduction to Azure70 533 - Module 01 - Introduction to Azure
70 533 - Module 01 - Introduction to Azure
 
Ebook 70 533 implementing microsoft infrastructure solution
Ebook 70 533 implementing microsoft infrastructure solutionEbook 70 533 implementing microsoft infrastructure solution
Ebook 70 533 implementing microsoft infrastructure solution
 
C#.net
C#.netC#.net
C#.net
 
Top 9 c#.net interview questions answers
Top 9 c#.net interview questions answersTop 9 c#.net interview questions answers
Top 9 c#.net interview questions answers
 
MVC 6 Introduction
MVC 6 IntroductionMVC 6 Introduction
MVC 6 Introduction
 
ASP.NET Brief History
ASP.NET Brief HistoryASP.NET Brief History
ASP.NET Brief History
 
Dotnet Basics Presentation
Dotnet Basics PresentationDotnet Basics Presentation
Dotnet Basics Presentation
 

Similaire à Asp.Net MVC Framework Guide

Introduction To Mvc
Introduction To MvcIntroduction To Mvc
Introduction To MvcVolkan Uzun
 
MVC From Beginner to Advance in Indian Style by - Indiandotnet
MVC From Beginner to Advance in Indian Style by - IndiandotnetMVC From Beginner to Advance in Indian Style by - Indiandotnet
MVC From Beginner to Advance in Indian Style by - IndiandotnetIndiandotnet
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentationivpol
 
ASP.NET MVC introduction
ASP.NET MVC introductionASP.NET MVC introduction
ASP.NET MVC introductionTomi Juhola
 
ASP.net MVC CodeCamp Presentation
ASP.net MVC CodeCamp PresentationASP.net MVC CodeCamp Presentation
ASP.net MVC CodeCamp Presentationbuildmaster
 
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...SoftServe
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVCSunpawet Somsin
 
ASP .NET MVC
ASP .NET MVC ASP .NET MVC
ASP .NET MVC eldorina
 
Simple mvc4 prepared by gigin krishnan
Simple mvc4 prepared by gigin krishnanSimple mvc4 prepared by gigin krishnan
Simple mvc4 prepared by gigin krishnanGigin Krishnan
 
MVC ppt presentation
MVC ppt presentationMVC ppt presentation
MVC ppt presentationBhavin Shah
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC PresentationVolkan Uzun
 
Getting Started with Zend Framework
Getting Started with Zend FrameworkGetting Started with Zend Framework
Getting Started with Zend FrameworkJuan Antonio
 
Adding a view
Adding a viewAdding a view
Adding a viewNhan Do
 
ASP.NET MVC Fundamental
ASP.NET MVC FundamentalASP.NET MVC Fundamental
ASP.NET MVC Fundamentalldcphuc
 
Developing ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller PatternDeveloping ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller Patterngoodfriday
 

Similaire à Asp.Net MVC Framework Guide (20)

Introduction To Mvc
Introduction To MvcIntroduction To Mvc
Introduction To Mvc
 
Asp.net mvc
Asp.net mvcAsp.net mvc
Asp.net mvc
 
MVC From Beginner to Advance in Indian Style by - Indiandotnet
MVC From Beginner to Advance in Indian Style by - IndiandotnetMVC From Beginner to Advance in Indian Style by - Indiandotnet
MVC From Beginner to Advance in Indian Style by - Indiandotnet
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 
ASP.NET MVC introduction
ASP.NET MVC introductionASP.NET MVC introduction
ASP.NET MVC introduction
 
ASP.net MVC CodeCamp Presentation
ASP.net MVC CodeCamp PresentationASP.net MVC CodeCamp Presentation
ASP.net MVC CodeCamp Presentation
 
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
MVC 4
MVC 4MVC 4
MVC 4
 
ASP .NET MVC
ASP .NET MVC ASP .NET MVC
ASP .NET MVC
 
Simple mvc4 prepared by gigin krishnan
Simple mvc4 prepared by gigin krishnanSimple mvc4 prepared by gigin krishnan
Simple mvc4 prepared by gigin krishnan
 
MVC ppt presentation
MVC ppt presentationMVC ppt presentation
MVC ppt presentation
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 
Getting Started with Zend Framework
Getting Started with Zend FrameworkGetting Started with Zend Framework
Getting Started with Zend Framework
 
Adding a view
Adding a viewAdding a view
Adding a view
 
ASP.NET MVC Fundamental
ASP.NET MVC FundamentalASP.NET MVC Fundamental
ASP.NET MVC Fundamental
 
MVC
MVCMVC
MVC
 
Asp.net mvc
Asp.net mvcAsp.net mvc
Asp.net mvc
 
Jinal desai .net
Jinal desai .netJinal desai .net
Jinal desai .net
 
Developing ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller PatternDeveloping ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller Pattern
 

Plus de Stefano Paluello

A gentle introduction to the world of BigData and Hadoop
A gentle introduction to the world of BigData and HadoopA gentle introduction to the world of BigData and Hadoop
A gentle introduction to the world of BigData and HadoopStefano Paluello
 
Using MongoDB with the .Net Framework
Using MongoDB with the .Net FrameworkUsing MongoDB with the .Net Framework
Using MongoDB with the .Net FrameworkStefano Paluello
 
Teamwork and agile methodologies
Teamwork and agile methodologiesTeamwork and agile methodologies
Teamwork and agile methodologiesStefano Paluello
 

Plus de Stefano Paluello (6)

Clinical Data and AI
Clinical Data and AIClinical Data and AI
Clinical Data and AI
 
A gentle introduction to the world of BigData and Hadoop
A gentle introduction to the world of BigData and HadoopA gentle introduction to the world of BigData and Hadoop
A gentle introduction to the world of BigData and Hadoop
 
Grandata
GrandataGrandata
Grandata
 
How to use asana
How to use asanaHow to use asana
How to use asana
 
Using MongoDB with the .Net Framework
Using MongoDB with the .Net FrameworkUsing MongoDB with the .Net Framework
Using MongoDB with the .Net Framework
 
Teamwork and agile methodologies
Teamwork and agile methodologiesTeamwork and agile methodologies
Teamwork and agile methodologies
 

Dernier

UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 

Dernier (20)

UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 

Asp.Net MVC Framework Guide

  • 1. Asp.Net MVC A new “pluggable” web framework Stefano Paluello stefano.paluello@pastesoft.com http://stefanopaluello.wordpress.com Twitter: @palutz
  • 2. MVC and Asp.Net The Model, the View and the Controller (looks like “The Good, the Bad and the Ugly” ) HtmlHelper and PartialView Routing Filters TDD with Asp.Net MVC Agenda
  • 3. MVC and Asp.Net From WebForm to MVC
  • 4. Asp.Net Asp.Net was introduced in 2002 (.Net 1.0) It was a big improvement from the “spaghetti code” that came with Asp classic It introduced a new programming model, based on Events, Server-side Controls and “stateful” Form (Session, Cache, ViewState): the RAD/VB-like development model for the web. It allowed a lot of developers to deal with the Web, also if they have limited or no skills at all in HTML and JavaScript. Build with productivity in mind
  • 5. Windows Form and Web Form models Server Reaction Code Action Server HttpRequest Serialize/ Deserialize Webform state Code HttpResponse
  • 6. Events and State management are not HTTP concepts (you need a quite big structure to manage them) The page life cycle, with all the events handler, can become really complicated and also delicate (easy to break) You have low control over the HTML code generated The complex Unique ID values for the server-side controls don’t fit well with Javascript functions There is a fake feeling of separation of concerns with the Asp.Net’s code behind Automated test could be challenging. That’s cool… But
  • 7. Web standards HTTP CSS Javascript REST (Representational State Transfer), represents an application in terms of resources, instead of SOAP, the Asp.Net web service base technology Agile and TDD The Web development today is
  • 9. Asp.Net MVC “tenets” Be extensible, maintainable and flexible Be testable Have a tight control over HTML and HTTP Use convention over configuration DRY: don’t repeat yourself Separation of concerns
  • 11. Separation of concerns Separation of concerns comes naturally with MVC Controller knows how to handle a request, that a View exist, and how to use the Model (no more) Model doesn’t know anything about a View View doesn’t know there is a Controller
  • 12. Asp.Net > Asp.Net MVC Based on the .Net platform (quite straightforward  ) Master page Forms authentication Membership and Role providers Profiles Internationalization Cache Asp.Net MVC is built on (the best part of) Asp.Net
  • 13. Asp.Net and Asp.Net MVC run-time stack
  • 14. Demo First Asp.NetMVC application
  • 15. Asp.Net MVC The structure of the project
  • 16. Asp.Net MVC projects have some top-level (and core) directories that you don’t need to setup in the config: Controllers, where you put the classes that handle the request Models, where you put the classes that deal with data Views, where you put the UI template files Scripts, where you put Javascript library files and scripts (.js) Content, where you put CSS and image files, and so on App_Data, where you put data files Convention over configuration
  • 18. The Models Classes that represent your application data Contain all the business, validation, and data acccess logic required by your application Three different kind of Model: data being posted on the Controller data being worked on in the View domain-specific entities from you business tier You can create your own Data Model leveraging the most recommend data access technologies The representation of our data
  • 19. An actual Data Model using Entity Framework 4.0
  • 20. ViewModel Pattern Additional layer to abstract the data for the Views from our business tier Can leverage the strongly typed View template features The Controller has to know how to translate from the business tier Entity to the ViewModel one Enable type safety, compile-time checking and Intellisense Useful specially in same complex scenarios Create a class tailored on our specific View scenarios
  • 21. publicActionResultCustomer(int id) { ViewData[“Customer”] = MyRepository.GetCustomerById(id); ViewData[“Orders”] = MyRepository.GetOrderforCustomer(id); return View(); } publicclassCustomerOrderMV { Customer CustomerData {get; set;} Order CustomerOrders{ get; set;} } publicActionResult Customer(int id) { CustomerOrderMVcustOrd = MyRepository.GetCustomerOrdersById(id); ViewData.Model = custOrd; return View(); } Model vs.ViewModel
  • 22. Validation Validation and business rule logic are the keys for any application that work with data Schema validation comes quite free if you use OR/Ms Validation and Business Rule logic can be quite easy too using the Asp.Net MVC 2 Data Annotations validation attributes (actually these attributes were introduced as a part of the Asp.Net Dynamic Data) Adding Validation Logic to the Models
  • 23. [MetadataType(typeof(Blog_Validation))] publicpartialclassBlog { } [Bind(Exclude = "IdBlog")] publicclassBlog_Validation { [Required(ErrorMessage= "Title required")] [StringLength(50, ErrorMessage = "…")] [DisplayName("Blog Title")] publicString Title { get; set; } [Required(ErrorMessage = "Blogger required")] [StringLength(50, ErrorMessage = “…")] publicString Blogger { get; set; }ù … } Data Annotations validation How to add validation to the Model through Metadata
  • 25. The controllers are responsible for responding to the user request Have to implement at least the IController interface, but better if you use the ControllerBaseor the Controller abstract classes (with more API and resources, like the ControllerContext and the ViewData, to build your own Controller) The Controllers
  • 26. using System; usingSystem.Web.Routing; namespaceSystem.Web.Mvc { // Summary:Defines the methods that are required for a controller. publicinterfaceIController { // Summary: Executes the specified request context. // Parameters: // requestContext:The request context. void Execute(RequestContextrequestContext); } } usingSystem.Web; usingSystem.Web.Mvc; publicclassSteoController : IController { publicvoid Execute(System.Web.Routing.RequestContextrequestContext) { HttpResponseBase response = requestContext.HttpContext.Response; response.Write("<h1>Hello MVC World!</h1>"); } } My own Controller
  • 27. publicinterfaceIHttpHandler { voidProcessRequest(HttpContext context); boolIsReusable { get; } } publicinterfaceIController { voidExecute(RequestContextrequestContext); } They look quite similar, aren’t they? The two methods respond to a request and write back the output to a response The Page class, the default base class for ASPX pages in Asp.Net, implements the IHttpHandler. This reminds me something…
  • 28. The Action Methods All the public methods of a Controller class become Action methods, which are callable through an HTTP request Actually, only the public methods according to the defined Routes can be called
  • 29. The ActionResult Actions, as Controller’s methods, have to respond to user input, but they don’t have to manage how to display the output The pattern for the Actions is to do their own work and then return an object that derives from the abstract base class ActionResult ActionResultadhere to the “Command pattern”, in which commands are methods that you want the framework to perform in your behalf
  • 30. The ActionResult publicabstract class ActionResult { public abstract voidExecuteResult(ControllerContext context); } publicActionResultList() { ViewData.Model= // get data from a repository returnView(); }
  • 31. ActionResult types EmptyResult ContentResult JsonResult RedirectResult RedirectToRouteResult ViewResult PartialViewResult FileResult FilePathResult FileContentResult FileStreamResult JavaScriptResult Asp.Net MVC has several types to help handle the response
  • 32. Demo Asp.Net MVC Controllers
  • 33. The Views are responsible for providing the User Interface (UI) to the user The View receive a reference to a Model and it transforms the data in a format ready to be presented The Views
  • 34. Asp.Net MVC’s View Handles the ViewDataDictionary and translate it into HTML code It’s an Asp.Net Page, deriving from ViewPage (System.Web.Mvc.ViewPage) which itself derives from Page (System.Web.UI.Page) By default it doesn’t include the “runat=server”, that you can add by yourself manually, if you want to use some server controls in your View (better to use only the “view-only” controls) Can take advantage of the Master Page, building Views on top of the Asp.Net Page infrastructure
  • 35. Asp.Net MVC Views’ syntax You will use <%: %> syntax (often referred to as “code nuggets”) to execute code within the View template. There are two main ways you will see this used: Code enclosed within <% %> will be executed Code enclosed within <%: %> will be executed, and the result will be output to the page
  • 36. Demo Views, Strongly Typed View, specify a View
  • 37. Html Helpers Html.Encode Html.TextBox Html.ActionLink, RouteLink Html.BeginForm Html.Hidden Html.DropDownList Html.ListBox Html.Password Html.RadioButton Html.Partial, RenderPartial Html.Action, RenderAction Html.TextArea Html.ValidationMessage Html.ValidationSummary Methods shipped with Asp.Net MVC that help to deal with the HTML code. MVC2 introduced also the strongly typed Helpers, that allow to use Model properties using a Lambda expression instead of a simple string
  • 38. Partial View Asp.Net MVC allow to define partial view templates that can be used to encapsulate view rendering logic once, and then reuse it across an application (help to DRY-up your code) The partial View has a .ascx extension and you can use like a HTML control
  • 39. The default Asp.Net MVC project just provide you a simple Partial View: the LogOnUserControl.ascx <%@ControlLanguage="C#"Inherits="System.Web.Mvc.ViewUserControl" %> <% if (Request.IsAuthenticated) { %> Welcome <b><%:Page.User.Identity.Name %></b>! [ <%:Html.ActionLink("Log Off", "LogOff", "Account") %> ] <% } else { %> [ <%:Html.ActionLink("Log On", "LogOn", "Account") %> ] <% } %> Partial View Example A simple example out of the box
  • 40. Ajax You can use the most popular libraries: Microsoft Asp.Net Ajax jQuery Can help to partial render a complex page (fit well with Partial View) Each Ajax routine will use a dedicated Action on a Controller With Asp.Net Ajax you can use the Ajax Helpers that come with Asp.Net MVC: Ajax.BeginForm AjaxOptions IsAjaxRequest … It’s not really Asp.Net MVC but can really help you to boost your MVC application
  • 41. Routing Routing in Asp.Net MVC are used to: Match incoming requests and maps them to a Controller action Construct an outgoing URLs that correspond to Contrller action How Asp.Net MVC manages the URL
  • 42. Routing vs URL Rewriting They are both useful approaches in creating separation between the URL and the code that handles the URL, in a SEO (Search Engine Optimization) way URL rewriting is a page centric view of URLs (eg: /products/redshoes.aspx rewritten as /products/display.aspx?productid=010) Routing is a resource-centric (not only a page) view of URLs. You can look at Routing as a bidirectional URL rewriting
  • 43. publicstaticvoidRegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new{ controller = "Home", action = "Index", id = UrlParameter.Optional} // Parameter defaults ); } protectedvoidApplication_Start() { AreaRegistration.RegisterAllAreas(); RegisterRoutes(RouteTable.Routes); } } Defining Routes The default one…
  • 45. StopRoutingHandler and IgnoreRoute You can use it when you don’t want to route some particular URLs. Useful when you want to integrate an Asp.Net MVC application with some Asp.Net pages.
  • 46. Filters Filters are declarative attribute based means of providing cross-cutting behavior Out of the box action filters provided by Asp.Net MVC: Authorize: to secure the Controller or a Controller Action HandleError: the action will handle the exceptions OutputCache: provide output caching to for the action methods
  • 47. Demo A simple Filter (Session Expire)
  • 48. TDD with Asp.Net MVC Asp.Net MVC was made with TDD in mind, but you can use also without it (if you want… ) A framework designed with TDD in mind from the first step You can use your favorite Test Framework With MVC you can test the also your UI behavior (!)
  • 49. Demo TDD with Asp.Net MVC
  • 50. Let’s start the Open Session:Asp.Net vs. Asp.Net MVC