The new "ASP. NET MVC 5 Framework" is officially published

Source: Internet
Author: User

ASP. NET MVC is a Web development framework built on an ASP. NET platform based on the MVC pattern, which provides a completely different approach to Web form development. The ASP. NET Web Form, drawing on the programming patterns of Windows Form based on control and event registration, makes WEB application development simple and fast, but it makes the nature of the developer and the Web far more gradual. ASP. NET MVC is a regression that enables developers to really program for the web, and we are no longer dragged into the Web page control, but the entire HTTP request and response process.

This is not an introductory book in the traditional sense.

After the publication of the ASP. NET MVC 4 Framework, the reader feeds their views, suggestions and comments to the author through a variety of channels. Some readers feel that the book is too "deep" for them, because they want to buy a simple introductory book, so I have to emphasize again-"This is not a traditional book of entry". If you have never been in contact with ASP. NET MVC and want to have a book that will allow you to master the basic programming patterns of ASP. NET MVC within two weeks, I don't think it is wise to choose this book.
I personally think that mastering ASP. NET MVC has 3 levels. Understand the basic programming patterns, master the way the controller and view are defined, know how the route is registered and how the validation rules are defined, this is the first level. The second level requires that we have a clear understanding of the whole process of the ASP. NET MVC framework itself from the request to receive responses, including how the request is routed, how the target controller is activated, how the model metadata is parsed, how the action method is executed, View how to render and so on. ASP. NET MVC itself is a very extensible development framework, reasonable use of its extensibility can solve many of the practical problems in development, and master the highest level of ASP. The best way to understand the framework itself is to find the appropriate extension points, and create the appropriate extensions to solve the problems we encountered.
This book is not a primer on ASP. NET MVC, but a book that allows readers at the first level to quickly enter the second and third levels. If you have access to a higher level of demand and have plenty of time to read, I am confident that you will be able to use this book to get something that is difficult for other similar books.
Many people think this book is too "deep", but I personally would rather say the book "Go Farther." Although this book touches the core of the ASP. NET-like framework more closely than other similar books, in its content itself, I think this book does not have anything "unfathomable". Although this book is not a purely introductory book, I will not exclude it from the reader's scope of the book according to the individual skill level of the reader. If the reader has basic. NET knowledge reserves, and has been engaged in the simple web development, reading this book will not have too big obstacle.

This is a book that tells the nature of the ASP. NET MVC Framework

A lot. NET developers are complaining that Microsoft development technology is too fast to update the frequency of their confusion, in fact, they see only a simple version upgrade, some of the essential things have been "stable." Microsoft launches. NET strategy has been more than 10 years, the CLR has only 4 versions. The latest version of ASP. Although the surface has not seen much initial shadow, but the entire request processing pipeline has never changed. For a development technology, as long as we understand its most fundamental things, not only should not be afraid of its high-frequency version replacement, but should warmly embrace it. This book seeks to bring the most fundamental things about the ASP. Rather than listing some simple programming techniques.

What is the difference between this book and the "ASP. NET MVC 4 framework"?

This book is intended for the latest version of ASP. NET MVC 5 provides new features and changes to the existing features of the ASP. NET MVC 4 are naturally reflected in this book. Information released through Microsoft's "official" channel we know that "feature routing" and "Authentication filter" are the two new features that ASP. NET MVC 5 provides, and we'll explain the feature routing in a separate chapter (13th "feature routing") in this book. The introduction to the authentication filter is placed in the new added chapter (12th "Filter").
In addition to these changes that have been learned through official channels, Microsoft has made a lot of improvements within the ASP. NET MVC 5 framework, which is only possible when we go deep into analyzing its source code. These "not known" content is also included in this book, if you have a copy of the "ASP. NET MVC 4 Framework Disclosure", in the reading of the contrast to know.
In addition to reflecting the changes in ASP. NET MVC 5 itself, this book complements some of the missing knowledge points in the previous version. In order to make readers better understand the contents of this book and to cater to most people's way of thinking, we have adjusted the structure of the whole book in the course of writing, and have made corresponding changes to some expressions.
Like most of ASP. NET MVC, the ASP. NET MVC 4 Framework introduces Web APIs in a separate chapter, which in fact creates a misconception for many readers that ASP. NET Web API is just ASP. The Affiliate product of MVC. In fact, not only do they use different message-processing pipelines on the run, and the two pipelines are also completely different in design, so there is nothing in this book that can be found about the ASP. If you want to learn more about the ASP. NET Web API, consider this book's sister article, "ASP. NET Web API 2 framework disclosure."

is this a practical book?

It may be felt that this book, which analyzes the workings of the ASP. NET MVC framework, has no "real" meaning, because our daily routine is programming, knowing that the entire processing process between ASP. NET MVC from request to response replies does not materially change our work. This is an extremely wrong idea. Learning a software development technology is like practicing a kung fu, not only to hard to attack the enemy moves, but also to study the heart heart. Programming mode is to attack the enemy moves, the framework behind the design principle is the internal strength of heart, no internal strength heart support moves can only be huaquanxiutui, and has a very high internal skills to master but can "no recruit wins the recruit."
In addition, since the program we write ultimately runs on the ASP. NET MVC framework, the efficiency of the program determines whether it will be able to "cater" to the framework's operating mechanism, so understanding how the ASP framework works can help us write high-quality programs.
Many readers ask why I have so much time and energy to learn more about different development frameworks (such as WCF, ASP, and ASP), which are actually related to the job. Over the years, the author's work in the company is to design, develop and maintain a set of internal development framework, the fundamental purpose of this framework is to allow us to adopt a pipeline-like project development approach, not only to improve the development efficiency, but also improve the quality of the project itself and reduce the requirements of the final developer skills, The way to achieve this is to let the final developer only care about the implementation of the specific business functions, all the non-business functions are done by the framework itself.
In order to accomplish this mission, we aim at. The development technology on the net platform has made many extensions. In order to accurately locate the extension points used, we have to have a deep understanding of the development technology itself, so in-depth learning. NET Platform Mainstream development technology is one of the author's essential work. In order to extend these practical services to the public, the authors have put these extensions into the relevant books. The author naturally does not share what we do directly (because it is illegal), so the extensions involved in the book are deliberately simplified, because the author does not want the reader to use these extensions directly, but to design the extensions you need based on the principles they embody.

some things outside of ASP. NET MVC

In the vicinity of the author, there are some people who have just graduated for a year or two graduates mainly. Most of them work hard, smart and studious, often holding the Gof "design mode", always want to apply the design patterns in the book to specific projects, or hope that through the project practice to confirm their design patterns in the book, but the distance between theory and practice is always confusing them.

. To learn the "practical" software architecture design knowledge from a real project or product, it is appropriate to first identify the architectural ideas and design patterns used in the target project or product, and many of the projects we participate in are in fact "architected" to a mess. For a product like ASP., its infrastructure can remain the same for a long time, and it proves the correctness of the architecture design applied above, aren't they the best material for our learning architecture design? This book provides an in-depth analysis of the operation mechanism of the ASP. NET MVC framework, in fact, the entire design of ASP. The reader may be able to read this book as a "schema design" book.
Many readers ask the author for a new development technology, how to master its "essence" more effectively. This is a question of learning methods, the author's personal use of learning methods can not be applied to all people. Nevertheless, the book also more or less reflects the author's personal use of learning methods, so in the discussion of a knowledge point, not only will tell the reader "what" and "why", but also tell the reader "How to prove it." In other words, the author will not only throw an argument to you, but will show you the whole process of the argument.

The writing characteristics of this book

and other similar book authors always from "static programming" as a point of entry, the author of "Dynamic Execution" perspective to examine the ASP. This book focuses on the process of processing requests by the framework itself, and strives to present the entire process of the ASP. NET MVC framework from receiving requests to responding to responses in a complete and clear manner to the reader. In the 1th chapter of this book, we have designed a "mini-version" of the ASP. NET MVC framework, which is intended to enable readers to have an overall understanding of the implementation pipeline of ASP. As for each part of the pipeline, the architecture design is described in detail through subsequent chapters, The principle of its execution in-depth analysis.
This book has a distinct feature from other Chinese original or translated books, which is that almost all of the terms are in English, such as Controller, action, and model, which are not translated into Chinese "controllers", "operations" and "models" in this book. Because I think a lot of terminology is difficult to find a semantically equivalent of the Chinese phrase or phrase corresponding to, for the accustomed to English as a "development language" of the reader, forced translation is actually unnecessary.
In addition, this is not a purely theoretical book, but an "empirical" book, in the book provides more than 100 individual examples can be downloaded for demonstration. These examples have different roles in this book, some to detect and prove the corresponding arguments, or to demonstrate some practical programming skills.


1th ASP. Net + MVC 1
1.1 Traditional MVC Mode 2
1.1.1 Autonomous View 2
1.1.2 What is MVC mode 3
Variants of 1.2 MVC 4
1.2.1 MVP 5
1.2.2 Model 2 13
1.2.3 ASP. NET MVC and Model 2 15
1.3 Iis/ Pipe 15
1.3.1 IIS 5.x with ASP. 16
1.3.2 IIS 6.0 and ASP. 17
1.3.3 IIS 7.0 and ASP. 19
1.3.4 ASP. NET Integration 20
1.3.5 ASP. NET Pipeline 22
1.4 How ASP. NET MVC is running 28
1.4.1 Web application built on "Mini Edition" ASP. 28
1.4.2 Routing 31
Activation of the 1.4.3 Controller 37
1.4.4 Action Execution 41

1.4.5 Complete Process 49
Chapter 2nd Routing 51
2.1 ASP. NET Route 52
2.1.1 Separation of request URLs from physical files 52
2.1.2 Example Demo: Mapping a request address to an. aspx page via Routing (s201) 53
2.1.3 Route and RouteTable 57
2.1.4 Routing Registration 65
2.1.5 generating URLs based on routing rules 77
2.2 ASP. NET MVC Route 79
2.2.1 Route Map 79
2.2.2 Route registration (S210) 80
2.2.3 Default URL parameter 83
2.2.4 area-based route mapping 85
2.2.5 Linking and URL generation 91
2.3 Dynamic HttpHandler Mapping 98
2.3.1 UrlRoutingModule 99
2.3.2 Pageroutehandler and Mvcroutehandler 100
2.3.3 ASP. NET Routing System Extension 101
2.3.4 Example Demo: Extend the ASP. NET routing system with custom route (s214) 102
3rd. Controller Activation 107
3.1 Controller activation System Panorama Show 108
3.1.1 Controller 108
3.1.2 Controllerfactory 114
3.1.3 Controllerbuilder 115
Activation and routing of the 3.1.4 Controller 122
3.2 Controller default activation mechanism 125
3.2.1 Controller Type Resolution 125
3.2.2 Controller type of cache 130
3.2.3 Controller Release and session state behavior Control 131
Application of the 3.3 IOC 133
3.3.1 from Unity to meet IOC 133
Decoupling of the 3.3.2 controller from model 135
3.3.3 IOC-based Controllerfactory 137
3.3.4 IOC-based Controlleractivator 143
3.3.5 IOC-based Dependencyresolver 145
4th Analysis of Model metadata 149
4.1 Model Meta Data 150
4.1.1 Model meta-data hierarchy structure 150
4.1.2 Model Meta Data customization 154
4.1.3 Imetadataaware Interface 171
4.2 Presentation of Templated Data 176
4.2.1 Example Demo: Displaying a Boolean value as RadioButton (s409) through a template 176
4.2.2 Pre-defined templates 178
4.2.3 Templates for data types 185
4.2.4 data type name v.s. Template Name 189
4.2.5 template acquisition and execution 193
4.2.6 Example Demo: Implementing predefined list rendering with custom model metadata and custom templates (s412) 197
4.3 Model metadata provision mechanism 205
4.3.1 again on Modelmetadata 206
4.3.2 Modelmetadataprovider 210
4.3.3 Model Metadata provides an extension of the system 214
5th 3 Important Descriptive Objects 217
5.1 Controllerdescriptor 218
5.1.1 Reflectedcontrollerdescriptor 219
5.1.2 Reflectedasynccontrollerdescriptor 228
5.2 Actiondescriptor 229
5.2.1 Asyncactiondescriptor 230
5.2.2 Reflectedactiondescriptor 231
5.2.3 Reflectedasyncactiondescriptor 232
5.2.4 Taskasyncactiondescriptor 233
5.3 Parameterdescriptor 234
Chapter 6th Binding of Model (i) 236
6.1 Provision of source data 237
6.1.1 Namevaluecollectionvalueprovider 238
6.1.2 Dictionaryvalueprovider 246
6.1.3 Valueproviderfactory 254
6.1.4 Valueproviderfactories 255
6.2 Modelbinder and its delivery strategy 259
6.2.1 Modelbinder 259
6.2.2 Modelbinderprovider 265
6.2.3 Modelbinders 268
6.2.4 Custommodelbinderattribute 271
6.2.5 how the Modelbinder for the parameter is created 274
6.3 The implementation of the model binding 276
6.3.1 initialization of the binding context 277
6.3.2 settings for modelstate during binding 279
Chapter 7th Binding of Model (ii) 283
7.1 Binding Simple Objects 284
7.1.1 binding simple objects with Valueprovider 284
7.1.2 Example Demo: Binding Simple Type parameters with Mydefaultmodelbinder (s701) 286
7.2 Binding Complex Objects 289
7.2.1 hierarchical structure of complex objects 289
7.2.2 Recursive binding 291
7.2.3 Example Demo: Binding complex Type parameters with Mydefaultmodelbinder (s702, s703) 294
7.3 Binding Collection 297
7.3.1 binding for a collection of data items of the same name 297
7.3.2 Collection bindings for indexes 302
7.4 Binding Dictionaries 311
The 7.4.1 Dictionary is a collection of complex types 311
7.4.2 Model binding Policy for dictionary types 312
7.4.3 Example Demo: Using the Mydefaultmodelbinder binding dictionary type parameter (s707) 316
Chapter 8th Validation of Model (i) 318
8.1 Several parameter verification methods 319
8.1.1 Modelerror 319
8.1.2 Validation Message Rendering 320
8.1.3 manually verifying the parameters of the binding 322
8.1.4 using the Validationattribute feature 327
8.1.5 let data type implement Ivalidatableobject interface 330
8.1.6 let data type implement IDataErrorInfo interface 332
8.2 Modelvalidator and its delivery strategy 334
8.2.1 Modelvalidator and Modelvalidatorprovider 334
8.2.2 Dataannotationsmodelvalidator 337
8.2.3 Validatableobjectadapter 337
8.2.4 Dataerrorinfomodelvalidator 338
8.2.5 Clientmodelvalidator 339
8.2.6 Compositemodelvalidator 341
Implementation of 8.3 model validation 345
8.3.1 validation in the model binding process 346
8.3.2 Example Demo: Validating validation in model bindings (s810) 347
8.3.3 validation for "required" data members 351
Chapter 9th Validation of Model (ii) 354
9.1 Validationattribute Characteristics 355
How the 9.1.1 data is validated 356
9.1.2 a few common Validationattribute 358
9.1.3 uniqueness of the application of the Validationattribute feature
9.2 Dataannotationsmodelvalidator and its delivery strategy 364
9.2.1 "fit" type Dataannotationsmodelvalidator 365
9.2.2 Dataannotationsmodelvalidatorprovider 368
9.2.3 applying the Validationattribute attribute to the parameter 375
9.2.41 model types, multiple validation rules 382
9.3 Client Authentication 389
9.3.1 jquery Validation 390
9.3.2 model validation based on jquery 394
9.3.3 Custom Validation 398
10th. Action Method Execution 402
10.1 Definition of an asynchronous action 403
10.1.1 request processing mechanism based on thread pool 403
10.1. Definition of 22 types of asynchronous action methods 404
10.1.3 Asyncmanager 406
10.2 Various synchronous and asynchronous components 412
10.2.1 Mvchandler 412
10.2.2 Controller 413
10.2.3 Actioninvoker 414
10.2.4 Controllerdescriptor 420
10.2.5 Actiondescriptor 423
10.3 Execution of the target method 430
The 10.3.1 action method does not perform in "Reflection" mode 430
10.3.2 Example Demo: Executing an action method on an expression tree (s1010) 432
11th. View Rendering 437
11.1 ActionResult 438
11.1.1 Emptyresult 438
11.1.2 Contentresult 439
11.1.3 Fileresult 446
11.1.4 Javascriptresult 451
11.1.5 Jsonresult 455
11.1.6 Httpstatuscoderesult 457
11.1.7 Redirectresult/redirecttorouteresult 458
11.2 Viewresult and Viewengine 461
View 461 in the 11.2.1 view engine
11.2.2 Viewengine 463
11.2.3 Viewresult's execution 465
11.3 Razor Engine 474
11.3.1 View's compilation principle 475
11.3.2 Webviewpage and Webviewpage[tmodel] 480
11.3.3 Razorview 485
11.3.4 Razorviewengine 495
12th Chapter Filter 499
12.1 Filter and its supply mechanism 500
12.1.1 Filter and Filterprovider 500
12.1.2 Registering filters by feature 502
12.1.3 controller itself is the filter 504
12.1.4 Global Registration of filters 504
12.1.5 Example Demo: Verifying the supply mechanism and execution order of filter (s1201,s1202,s1203) 506
12.2 Authenticationfilter 511
12.2.1 Authenticationfilter Implementation Process 512
12.2.2 Example Demo: Implementing basic Certification with custom Authenticationfilter (s1204) 513
12.3 Authorizationfilter 518
12.3.1 Authorizeattribute 518
12.3.2 Requirehttpsattribute 520
12.3.3 Validateinputattribute 520
12.3.4 Validateantiforgerytokenattribute 523
12.3.5 Childactiononlyattribute 527
12.4 Actionfilter 528
12.4.1 Actionfilter Implementation Process 529
12.4.2 actionfilter settings for ActionResult 530
12.4.3 Exception Handling 532
12.5 Exceptionfilter 534
12.5.1 Handleerrorattribute 535
12.5.2 Example Demo: Using a custom Exceptionfilter Integrated Enterprise Library for exception handling (s1207, s1208, s1209) 537
12.6 Resultfilter and Overridefilter 551
12.6.1 Resultfilter Implementation Process 552
12.6.2 Shielding Peripheral Filter 553
13th feature Routing 556
13.1 Feature Routing Registration 557
13.1.1 Routeinfoprovider Characteristics 557
13.1.2 Basic route Mapping 558
13.1.3 make way by template to reflect the hierarchy of resources as much as possible 559
13.1.4 setting constraints for route variables 560
13.1.5 default route variable 561
13.1.6 Setting the template prefix 562
13.1.7 Setting the area name 563
13.2 Parsing of constraint expressions 564
13.2.1 Rangerouteconstraint 565
13.2.2 Inlineconstraintresolver 566
13.2.3 Custom Constraints 570
Creation of the 13.3 route 574
13.3.1 attribute route registered route Object 574
13.3.2 Route generation Mechanism 579
Activation of the 13.3.3 controller and selection of the action method 579
The 14th chapter of case Practice 581
14.1 Feature Introduction 582
14.1.1 the rendering of the product list 582
14.1.2 Order Items 584
14.1.3 Login and error page 585
14.2 Design Overview 586
14.2.1 controller-service-repository 586
Application of the 14.2.2 IOC 591
Application of 14.2.3 AOP 594
14.2.4 Exception Handling 601
14.3 Programming Implementation 602
14.3.1 Creating a data table 603
14.3.2 Repository 604
14.3.3 Service 609
14.3.4 routing registration and layout 612
14.3.5 Productcontroller 616
14.3.6 Ordercontroller 624
14.3.7 AccountController 630

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.