Thứ Năm, 5 tháng 3, 2015

[ ASP.NET MVC 4 in Action ] Part 1: Những nguyên tắc cơ bản nhanh

Part 1
Những nguyên tắc cơ bản nhanh
Phần 1 là phần dành cho những người chưa làm việc nhiều với ASP.NET MVC và cần xem lại mọi khái niệm riêng biệt trước khi sử dụng chúng với nhau. Liệu có hay không bạn đã theo dõi một vài hướng dẫn có sẵn trên http://www.asp.net/mvc, bạn sẽ tìm thấy những chương trong phần 1 rất dễ để theo dõi. Đừng tưởng phần 1 chỉ dành cho những người mới. Chúng ta sẽ đi rất nhanh từ việc tạo project  ASP.NET MVC đầu tiên của bạn thông qua việc khám phá sâu tất cả các khái niệm chính. Trước khi bạn bắt đầu chương 1, bạn sẽ muốn cài đặt ASP.NET MVC 4 và Visual Studio 2010 hoặc 2011.

Trong chương 1, chúng ta đi thông qua 1 … (In chapter 1, we walk through a beginner ramp-up), bao gồm các vấn đề cơ bản của mô hình MVC và việc hiện thực ASP.NET MVC. Chương 2 đưa bạn thông qua việc hiện thực một ví dụ Hello World đơn giản. Tiếp theo, chương 3 bao gồm các nguyên tắc cơ bản của MVC views, bao gồm tạo strongly typed view models và một vài tính năng trong Razor view engine. Chương 4 giới thiệu các vấn đề cơ bản của Controllers: xử lý requests, form posts và đưa thông tin tới View. Một khi bạn hiểu những nguyên tắc cơ bản của ASP.NET MVC, bạn có thể tự tin chuyển đến phần 2, cái sẽ sắp lớp thêm những khái niệm tổ hợp (which will layer on more combinatory concepts).

[ ASP.NET MVC 4 in Action ] Phần mở đầu & mục lục

Praise for Earlier Editions of
ASP.NET MVC in Action
Lời khen cho các phiên bản trước của
ASP.NET MVC in Action

Một nguồn đáng tin cậy cho ASP.NET MVC 2. Hãy chọn cuốn sách này!
—Alessandro Gallo, Microsoft MVP

ASP.NET MVC
2 in Action rất tốt để đọc và là  nguồn tài liệu tham khảo vô giá.
—Derek Jackson, Software Architect, Harvard-Westlake

Học MVC với những người có công định hình lên nó Hãy sẵn sàng để tìm hiểu thêm MVC trong phần tiếp theo tuyệt vời này.
—Alex Thissen, Killer-Apps

Thật dễ dàng với nguồn tài nguyên MVC sẵn có này! Được hội tụ bởi những thứ tốt nhất và nó tốt đến nỗi có thể bạn sẽ cần mua 2 bản.
—Andrew Siemer, Software Architect, Lamps Plus

Giải thích một cách đầy đủ các khái niệm cơ bản về MVC và  thực hành phát triển tốt nhất.
—Tetsuo Torigai, Developer, Torigai Consulting

Quyển sách này không chỉ giải thích sử dụng Microsoft’s
MVC  như thế nào, nó dạy cách thực hành, giúp những nhà phảt triển có thể tạo ra thêm nhiều project có thể bảo trì.
—Anne Epstein, Senior Consultant, Headspring

ASP.NET in Action là cuốn sách phải đọc cho những ai nghiêm túc về phát triển với nền tảng ASP.NET MVC.
—Steve Michelotti, Microsoft MVP, geekswithblogs.net

Chỉ với 300 trang,
ASP.NET MVC in Action thật sự là một kiệt tác…. Các tác giả được coi là những ngôi sao hang đầu trong cộng đồng ASP.NET và hộ đã mở ra cánh của cho buổi hòa nhạc của họ với ASP.NET MVC in Action.
—Mohammad Azam, Microsoft MVP

Cuốn sách là một việc làm tốt, không chỉ cho bạn thấy cái để làm mà nó còn đưa ra những cảnh báo để tránh những cách làm tệ có thể dẫn đến các vấn để về bảo trì trên những ứng dụng không tầm thường
—Venkat Subramanian, NoFluffJustStuff Blogs

Tôi thực sự thích
ASP.NET MVC in Action và đề cao nó cho một cái nhìn mới về nền tảng ASP.NET MVC.
—David Hayden, Microsoft MVP

ASP.NET MVC in Action sẽ hướng dẫn bạn từ project đầu tiên thông qua những chủ đề như AJAX và triển khai lên các môi trường hosting tối ưu. Phong cách viết rõ rang vào súc tích. Sơ đồ và các mã nguồn ví dụ thì phong phú Tôi đề nghị nó cho bất cứ ai đang tìm kiếm một nguồn tài liệu tuyệt vời để học hay trở thành một người sử dụng tốt hơn của nền tảng ASP.NET MVC.
—Nathan Stott, Partner and Software Engineer, Whiteboard-IT
 Tôi rất hài lòng với cuốn sách này. Tôi chắc chẵn sẽ đề nghị nó tới bất cứ ai yêu thích ASP.NET MVC. Getting beyond the text that comes with the CodeCampServer is just icing on the cake. (Đoạn này khó dịch quá, nếu không nhầm thì ý là dễ như ăn bánh thì phải)
—Chris Stewart, CompiledMonkey.com

Các tác giả không chỉ làm một công việc xuất sắc là đặt các hướng dẫn thực hành tuyệt vời của ASP.NET MVC lại với nhau, họ còn đưa vào thành công một số khái niệm lật đổ
ALT.NET. Cái mà sẽ làm chúng ta thành những nhà phát triển tốt hơn. Và vào cuối cái ngày đó, đó sẽ là một thành tựu tốt chết tiệt.
—Bobby Johnson, AppExtremes
.Như sự giới thiệu đầu tiên của tôi tới MVC, tôi tìm thấy cuốn sách này rất dễ đọc và hấp dẫn.
—Roger Wright, Engineering Manager, Aha Macav Power Service



ASP.NET MVC 4
in Action
A revised edition of ASP.NET MVC 2 in Action
Một phiên bản được sửa đổi của ASP.NET MVC 2 in Action

JEFFREY PALERMO, JIMMY BOGARD
ERIC HEXTER, MATTHEW HINZE
AND JEREMY SKINNER



brief contents (Nội dung ngắn gọn)
PART 1 HIGH-SPEED FUNDAMENTALS
1 Introduction to ASP.NET MVC
2 Hello MVC world
3 View fundamentals
4 Action-packed controllers
PART 2 WORKING WITH ASP.NET MVC
5 View models
6 Validation
7 Ajax in ASP.NET MVC
8 Security
9 Controlling URLs with routing
10 Model binders and value providers
11 Mapping with AutoMapper
12 Lightweight controllers
13 Organization with areas
14 Third-party components
15 Data access with NHibernate
PART 3 MASTERING ASP.NET MVC
16 Extending the controller
17 Advanced view techniques
18 Dependency injection and extensibility
19 Portable areas
20 Full system testing
21 Hosting ASP.NET MVC applications
22 Deployment techniques
23 Upgrading to ASP.NET MVC 4
24 ASP.NET Web API



Contents
foreword
foreword to the second edition
foreword to the first edition
preface
acknowledgments
about this book
about the authors
about the cover illustration
PART 1 HIGH-SPEED FUNDAMENTALS
1 Introduction to ASP.NET MVC
1.1 Setting the stage
The .NET platform ■  ASP.NET Web Forms
1.2 What is ASP.NET MVC?
The MVC pattern ■  Benefits of ASP.NET MVC
1.3 What’s new in ASP.NET MVC 3/4?
The Razor view engine■  Package management with NuGet Improved extensibility■  Global action filters■  Dynamic language features■  Partial page output caching  Ajax improvements ■  Validation improvements
1.4 Summary

2 Hello MVC world
2.1 Setting up your development environment
Installing MVC using the Web Platform Installer
2.2 Creating your first MVC application
Creating a new project 15 A tour of the default project template
Controllers, actions, and displaying dynamic content
2.3 The Guestbook sample application
Creating the database.  Adding the model  Accepting
guestbook entries
Displaying guestbook entries
Customizing the look and feel with layouts
2.4 Summary
3 View fundamentals
3.1 Introducing views
Selecting a view to render 39 Overriding the view name
3.2 Passing data to views
Examining the ViewDataDictionary The ViewBag
Strongly typed views with a view model
Displaying view model
data in a view
3.3 Using strongly typed templates
EditorFor and DisplayFor templates ■  Built-in templates
Selecting templates
■  Customizing templates
3.4 Summary
4 Action-packed controllers
4.1 Exploring controllers and actions
IController and the controller base classes What makes an action method 62
4.2 What should be in an action method?
Manually mapping view models ■  Input validation
4.3 Introduction to unit testing
Using the provided test project  Testing the GuestbookController
4.4 Summary

PART 2 WORKING WITH ASP.NET MVC
5 View models
5.1 What is a view model?
The online store example  Building the view model
Delivering the presentation model
ViewData.Model
5.2 Representing user input
Designing the model  Presenting the input model in a
view  
Working with the submitted input
5.3 More complex models for both display and input
Designing a combined display and input model  Working with the input model
5.4 Summary
6 Validation
6.1 Server-side validation
Validation with Data Annotations  Extending the ModelMetadataProvider
6.2 Client-side validation
Getting started with client-side validation  Using RemoteAttribute  Creating custom client-side validators
6.3 Summary
7 Ajax in ASP.NET MVC
7.1 Ajax with jQuery
jQuery primer■  Using jQuery to make Ajax requests
Progressive enhancement
■  Using Ajax to submit form data
7.2 ASP.NET MVC Ajax helpers
Ajax.ActionLink■  Ajax.BeginForm. Ajax options
Differences from earlier versions of ASP.NET MVC
7.3 Ajax with JSON and client templates
Ajax with JSON ■  Client-side template ■  Finishing touches
7.4 Creating an autocomplete text box
Building the CitiesController
7.5 Summary
8 Security
8.1 Authentication and authorization
Restricting access with the AuthorizeAttribute
AuthorizeAttribute—how it works
8.2 Cross-site scripting (XSS)
XSS in action Avoiding XSS vulnerabilities
8.3 Cross-site request forgery (XSRF)
XSRF in action■  Preventing XSRF■  JSON hijacking
8.4 Summary
9 Controlling URLs with routing
9.1 Introducing URL routing
The default routeInbound and outbound routing
9.2 Designing a URL schema
Make simple, clean URLs Make hackable URLs Differentiate requests using URL parameters Avoid exposing database IDs wherever possibl ■  Consider adding unnecessary information
9.3 Implementing routes in ASP.NET MVC
URL schema for an online store  ■  Adding a custom static route Adding a custom dynamic route  Catch-all routes
9.4 Using the routing system to generate URLs
9.5 Routing with ASP.NET Web Forms
Adding routes for Web Forms pages■  Generating URLs from Web Forms pages
9.6 Debugging routes
Installing Route Debugger ■  Using Route Debugger
Using route constraints
9.7 Testing route behavior
Testing inbound routes■  Testing outbound routes
9.8 Summary
10 Model binders and value providers 185
10.1 Creating a custom model binder
10.2 Using custom value providers
10.3 Summary
11 Mapping with AutoMapper
11.1 Life before AutoMapper
11.2 Introducing AutoMapper
Mapping matching property names■  Flattening object hierarchies
11.3 AutoMapper basics
AutoMapper Initialization ■  AutoMapper profiles
Sanity checking
■  Reducing repetitive formatting code
Another look at our views
11.4 Summary
12 Lightweight controllers
12.1 Why lightweight controllers?
Easy to maintain■  Easy to test■  A focused responsibility
12.2 Techniques for simplifying controllers
Managing common view data■  Deriving action results
Using an application bus.
12.3 Summary
13 Organization with areas
13.1 Creating a basic area
13.2 Managing links and URLs with T4MVC
13.3 Summary
14 Third-party components
14.1 Learning about NuGet
Updating a package ■  Understanding NuGet basics
14.2 Using ASP.NET Web Helpers
14.3 The MvcContrib Grid component
Using the MvcContrib Grid ■  MvcContrib Grid advanced usage
14.4 Summary
15 Data access with NHibernate
15.1 Functional overview of reference implementation
15.2 Application architecture overview
15.3 Exploring the Core
15.4 NHibernate configuration–infrastructure of the application
NHibernate’s configuration■  The NHibernate mapping—simple but powerful■  Initializing the configuration
15.5 Presenting the model through the UI
15.6 Pulling it together
15.7 Summary
PART 3 MASTERING ASP.NET MVC
16 Extending the controller
16.1 Controller extensibility
16.2 Controller actions
16.3 Action, authorization, and result filters
16.4 Action selectors
16.5 Using action results to reduce complexity
Removing duplication with an action result■  Using action
results to abstract hard-to-test dependencies
16.6 Summary
17 Advanced view techniques
17.1 Eliminating duplication in the view
Layouts Partials Child actions
17.2 Building query-string parameter lists
17.3 Exploring the Spark view engine
Installing and configuring Spark Simple Spark view example
17.4 Summary
18 Dependency injection and extensibility
18.1 Introducing dependency injection
What is DI Using constructor injection Introducing interfaces■  Using a DI container
18.2 Using DI with ASP.NET MVC
Custom controller factories ■  Using the dependency resolver
18.3 Summary
19 Portable areas
19.1 NuGet packaging basics
A simple area to package Consuming portable areas
19.2 Creating an RSS widget with a portable area
Creating the RSS widget portable area example
19.3 Interacting with the portable area bus
Example of using the MvcContrib message bus
19.4 Summary
20 Full system testing
20.1 Testing the UI layer
Installing the testing software Walking through the test
manually
■  Automating the test■  Running the test
20.2 Building maintainable navigation
20.3 Interacting with forms
20.4 Asserting results
20.5 Summary
21 Hosting ASP.NET MVC applications
21.1 Hosting environments
21.2 XCOPY deployment
21.3 IIS 7
21.4 IIS 6 and 5.1
21.5 Azure hosting
What is Windows Azure, and how do I get it? Configuring the application for Azure deployment Packaging and deploying your application■  Accessing your application running in Windows Azure
21.6 Summary
22 Deployment techniques
22.1 Employing continuous integration
22.2 Enabling push-button XCOPY deployments
22.3 Managing environment configurations
22.4 Enabling remote server deployments with Web Deploy
22.5 Summary
23 Upgrading to ASP.NET MVC 4
23.1 Runtime view selection with DisplayModes
Using the Mobile DisplayMode Creating new DisplayModes
Empowering users to override DisplayModes
23.2 Combining and minifying client assets
23.3 Improvements to Razor
Automatic tilde-slash resolution Conditional attributes
23.4 Summary
24 ASP.NET Web API

24.1 What is Web API?
Why Web API? ■  How Web API is different from WCF
24.2 Adding web services to the Guestbook application
Creating a GET web service■  Creating POST web services
24.3 Web API alternative
24.4 Summary