Home Page Icon
Home Page
Table of Contents for
I. ASP.NET MVC fundamentals
Close
I. ASP.NET MVC fundamentals
by Dino Esposito
Programming Microsoft ASP.NET MVC
Dedication
Introduction
Who should read this book
Assumptions
Who should not read this book
Organization of this book
System requirements
Code samples
Installing the code samples
Using the code samples
Errata & book support
We want to hear from you
Stay in touch
I. ASP.NET MVC fundamentals
1. ASP.NET MVC controllers
Routing incoming requests
Simulating the ASP.NET MVC runtime
Defining the syntax of recognized URLs
Defining the behavior of the HTTP handler
Invoking the HTTP handler
The URL routing HTTP module
Superseding URL rewriting
Routing the requests
The internal structure of the URL routing module
Application routes
URL patterns and routes
Defining application routes
Processing routes
Route handler
Handling requests for physical files
Preventing routing for defined URLs
Attribute routing
The controller class
Aspects of a controller
Granularity of controllers
Stateless components
Further layering is up to you
Highly testable
Writing controller classes
From routing to controllers
From routing to actions
Actions and HTTP verbs
Action methods
Processing input data
Getting input data from the Request object
Getting input data from the route
Getting input data from multiple sources
The ValueProvider dictionary
Producing action results
Inside the ActionResult class
Predefined action result types
The mechanics of executing action results
Returning HTML markup
Returning JSON content
Summary
2. ASP.NET MVC views
The structure and behavior of a view engine
The mechanics of a view engine
Detecting registered view engines
Anatomy of a view engine
Who calls the view engine?
The view object
Definition of the view template
Resolving the template
Default conventions and folders
The template for the view
The master view
HTML helpers
Basic helpers
Rendering HTML forms
Rendering input elements
Action links
Partial views
The HtmlHelper class
Templated helpers
Flavors of a templated helper
The Display helpers
The Editor helpers
Custom helpers
The structure of an HTML helper
MvcHtmlString is better than just a string
A sample HTML helper
A sample Ajax helper
The Razor view engine
Inside the view engine
Search locations
Code nuggets
Special expressions of code nuggets
Conditional nuggets
The Razor view object
Designing a sample view
Defining the model for the view
Defining a master view
Defining sections
Default content for sections
Nested layouts
Declarative HTML helpers
Coding the view
Modeling the view
The ViewData dictionary
The ViewBag dictionary
Strongly typed view models
Packaging the view-model classes
Advanced features
Custom view engines
Render actions
Child actions
Summary
3. The model-binding architecture
The input model
Evolving from the Web Forms input processing
Role of server controls
Role of the view state
Input processing in ASP.NET MVC
The role of model binders
Flavors of a model
Model binding
Model-binding infrastructure
Analyzing the method’s signature
Getting the binder for the type
The default model binder
Binding primitive types
Dealing with optional values
Value providers and precedence
Binding complex types
Binding collections
Binding collections of complex types
Binding content from uploaded files
Customizable aspects of the default binder
The Bind attribute
Creating whitelists of properties
Creating blacklists of properties
Aliasing parameters by using a prefix
Advanced model binding
Custom type binders
Customizing the default binder
Implementing a model binder from scratch
Registering a custom binder
A sample DateTime model binder
The displayed data
The controller methods
Creating the DateTime binder
Summary
II. ASP.NET MVC software design
5. Aspects of ASP.NET MVC applications
ASP.NET intrinsic objects
HTTP response and SEO
Permanent redirection
Devising routes and URLs
The trailing slash
Managing the session state
Using the Session object
Never outside the controller
Caching data
The bright side and dark side of the native Cache object
Injecting a caching service
A better way of injecting a caching service
Distributed caching
Caching the method response
Partial output caching
Error handling
Handling program exceptions
Handling exceptions directly
Overriding the OnException method
Using the HandleError attribute
Global error handling
Global error handling from global.asax
Global error handling using an HTTP module
Intercepting model-binding exceptions
Handling route exceptions
Dealing with missing content
Catch-all route
Skipping IIS error-handling policies
Localization
Using localizable resources
Localizable text
Localizable files
Referencing embedded files
Localizable views
Dealing with localizable applications
Auto-adapting applications
Multilingual applications
Changing culture programmatically
Getting localized data from a service
Summary
6. Securing your application
Security in ASP.NET MVC
Authentication and authorization
Configuring authentication in ASP.NET MVC
Restricting access to action methods
Allowing anonymous callers
Handling authorization for action methods
Authorization and output caching
Hiding critical user interface elements
Separating authentication from authorization
Anonymous or not authorized?
Authentication filters
Implementing a membership system
Defining a membership controller
Validating user credentials
Integrating with the membership API
Using the SimpleMembership API
Integrating with the role API
ASP.NET identity
Authenticating users by using ASP.NET Identity
The Remember-Me feature and Ajax
Reproducing the problem
Solving the problem
External authentication services
The OpenID protocol
Identifying users through an OpenID provider
OpenID vs. OAuth
Authenticating via social networks
Registering your application with Twitter
Enabling social authentication in ASP.NET MVC
Starting the authentication process
Dealing with the Twitter response
From authentication to membership
Beyond authentication
Summary
7. Design considerations for ASP.NET MVC controllers
Shaping up your controller
Choosing the right stereotype
RDD at a glance
Breaking down the execution of a request
Acting as a “Controller”
Acting as a “Coordinator”
Fat-free controllers
Short is always better
Action methods coded as view-model builders
Worker services
Implementing a worker service
Do we really need controllers?
The ideal action method code
Connecting the presentation and back end
The Layered Architecture pattern
Beyond classic layers
The (idiomatic) presentation layer
The application layer
The domain layer
Exposing entities of the domain
The infrastructure layer
Injecting data and services in layers
The Dependency Inversion Principle
The Service Locator pattern
The Dependency Injection pattern
Using tools for Inversion of Control
The poor-man’s DI
Gaining control of the controller factory
Registering a custom controller factory
Building a custom controller factory
A Unity-based controller factory
Summary
8. Customizing ASP.NET MVC controllers
The extensibility model of ASP.NET MVC
The provider-based model
Gallery of extensibility points
A realistic scenario: alternate TempData storage
Using custom components in your applications
The Service Locator pattern
Service Locator vs. Dependency Injection
SL in ASP.NET MVC
Defining your dependency resolver
Adding aspects to controllers
Action filters
Embedded and external filters
Classification of action filters
Built-in action filters
Global filters
Gallery of action filters
Adding a response header
Compressing the response
View Selector
Special filters
Action name selectors
Action method selectors
Restricting a method to Ajax calls only
Restricting a method to a given submit button
Building a dynamic loader filter
Interception points for filters
Adding an action filter by using fluent code
Customizing the action invoker
Registering the custom invoker
Enabling dynamic loading via a filter provider
Action result types
Built-in action result types
Returning a custom status code
Returning JavaScript code
Returning JavaScript Object Notation data
Returning primitive types
Custom result types
Returning JSONP Strings
Returning syndication feed
Dealing with binary content
Returning PDF files
Summary
9. Testing and testability in ASP.NET MVC
Testability and design
DfT
The attribute of control
The attribute of visibility
The attribute of simplicity
Loosen up your design
Interface-based programming
Relativity of software testability
Testability and coupling
Testability and object orientation
The basics of unit testing
Working with a test harness
Choosing a test environment
Test fixtures
Arrange, act, assert
Data-driven tests
Aspects of testing
Very limited scope
Testing in isolation
Fakes and mocks
Number of assertions per test
Testing inner members
Code coverage
Testing your ASP.NET MVC code
Which part of your code should you test?
How do I find relevant code to test?
The domain layer
The orchestration layer
The data access layer
Unit testing ASP.NET MVC code
Testing whether the returned view is correct
Testing localization
Testing redirections
Testing routes
Dealing with dependencies
About mock and fake objects
Testing code that performs data access
Mocking the HTTP context
Mocking the HttpContext object
Mocking the Request object
Mocking the Response object
Mocking the Session object
Mocking the Cache object
Summary
10. An executive guide to Web API
The whys and wherefores of Web API
The need for a unified HTTP API
Beyond WCF
What Web API means for client applications
What Web API means for ASP.NET Web Forms applications
MVC controllers vs. Web API
The Controller class does it all
Feeling the difference
Building RESTful applications
Putting Web API to work
Designing a RESTful interface
Defining the resource type
The ApiController Class
Routing to action methods
Dealing with multiple matches
Active naming conventions
Expected method behavior
Semantic of POST methods
Semantic of PUT methods
Semantic of DELETE methods
Semantic of other methods
Using the Web API
Invoking Web API from JavaScript
Invoking from server-side code
Making the call asynchronous
Designing an RPC-oriented Interface
CRUD-over-HTTP is just one option
Action attributes
Custom routes
Attribute routing
Turning on attribute routing
Security considerations
The host takes care of security
Using Basic authentication
Using access tokens
Using OAuth
Using cross-origin resource sharing
Negotiating the response format
The ASP.NET MVC approach
Understanding the requested format
Enforcing data and format separation
How content negotiation works in Web API
Involved HTTP headers
Changing default formatters
Defining formatters for specific types
Summary
III. Mobile clients
11. Effective JavaScript
Revisiting the JavaScript language
Language basics
The type system
Null vs. undefined
Local and global variables
Variables and hoisting
Objects
Functions
Object-orientation in JavaScript
Making objects look like classes
Using closures
Using prototypes
Plain custom objects vs. a hierarchy of classes
jQuery’s executive summary
DOM queries and wrapped sets
The root object
Running a query
Enumerating the content of a wrapped set
Selectors
Basic selectors
Compound selectors
Predefined filters
Filter vs. find
Chaining operations on a wrapped set
Events
Binding and unbinding
Live event binding
Page and DOM readiness
Aspects of JavaScript programming
Unobtrusive code
Style the view by using code
Pragmatic rules of unobtrusive JavaScript
Reusable packages and dependencies
The Namespace pattern
The Module pattern
Script and resource loading
The download is always synchronous
Scripts at the bottom
Dealing with static files
Using sprites
Bundling and minification
Bundling related resources
Bundling script files
Adding minification
Summary
12. Making websites mobile-friendly
Technologies for enabling mobile on sites
HTML5 for the busy developer
Semantic markup
What’s different in HTML5?
A native collapsible element
New input types
The <datalist> element
Local storage
Audio and video
RWD
Feature detection
CSS media queries
CSS media queries in action
Fluid layout
When RWD meets mobile
jQuery Mobile’s executive summary
Themes and styles
Data-* attributes
Pages in jQM
Header and footer
Lists, lists, and lists
Fluid layout
Collapsible panels
Twitter Bootstrap at a glance
Setting up Bootstrap
The grid system
Navigation bars
Embellishing the UI with icons and images
Drop-down menus
Button groups
Adding mobile capabilities to an existing site
Routing users to the correct site
The routing algorithm
Implementing the routing algorithm
Tracking the chosen route
Tweaking the configuration files
From mobile to devices
Summary
13. Building sites for multiple devices
Understanding display modes in ASP.NET MVC
Separated mobile and desktop views
Built-in support for mobile views
Default configuration for mobile views
Rules for selecting the display mode
Naming a display mode
The matching rule
Adding custom display modes
Listing current display modes
Going beyond the default configuration
Defining custom display modes
Introducing the WURFL database
Structure of the repository
The overall XML schema
Groups of capabilities
WURFL patch files
Essential WURFL capabilities
Identifying the current device
Serving browser-specific content
Using WURFL with ASP.NET MVC display modes
Configuring the WURFL framework
Installing the NuGet package
Referencing the device database
Initializing the WURFL runtime
Detecting device capabilities
Processing the HTTP request
Virtual capabilities
Accuracy vs. performance
Using WURFL-based display modes
Selecting display modes
Defining matching rules
A multidevice site in action
The WURFL cloud API
Setting up the API
Cloud API vs. on-premises API
Why you should consider server-side solutions
Summary
A. About the author
Index
About the Author
Copyright
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
Introduction
Next
Next Chapter
1. ASP.NET MVC controllers
Part I. ASP.NET MVC fundamentals
Chapter 1
Chapter 2
Chapter 3
Chapter 4
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset