pro_asp.net_mvc_3_framework.pdf

(8491 KB) Pobierz
763853530.005.png
Table of contents not currently available.
Changes from original ALPHA eBook:
- Basic Chapter Bookmars Added
- Created CoverPage
- Updated this info
The following chapters are present: 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,21,22,23
0,66,1* (The following chapters are misssing between 1 & 23)
Chapter 20: JQuery
C H A P T E R 1
n n n
What’s the Big Idea?
ASP.NET MVC is a web development framework from Microsoft that combines the effectiveness and tidiness of
model-view-controller (MVC) architecture, the most up-to-date ideas and techniques from agile development, and the
best parts of the existing ASP.NET platform. It’s a complete alternative to traditional ASP.NET Web Forms,
delivering considerable advantages for all but the most trivial of web development projects. In this chapter, you’ll
learn why Microsoft originally created ASP.NET MVC, how it compares to its predecessors and alternatives, and,
finally, what’s new in ASP.NET MVC 3.
A Brief History of Web Development
To understand the distinctive aspects and design goals of ASP.NET MVC, it’s worth considering the history of web
development so far—brief though it may be. Over the years, Microsoft’s web development platforms have
demonstrated increasing power—and (unfortunately) increasing complexity. As shown in Table 1–1, each new
platform tackled the specific shortcomings of its predecessor.
Table 1–1. Microsoft’s Lineage of Web Development Technologies
Period
Technology
Strengths
Weaknesses
Jurassic
Common Gateway Interface
(CGI) *
Simple
Runs outside the web
server, so is resource-
intensive (spawns a
separate OS process per
request)
Low-level
Flexible
Only option at the time
Bronze age
Microsoft Internet Database
Connector (IDC)
Runs inside web server
Just a wrapper for SQL
queries and templates for
formatting result sets
1996
Active Server Pages (ASP)
General-purpose
Interpreted at runtime
Encourages “spaghetti
code”
1
763853530.006.png 763853530.007.png
 
CHAPTER 1 n WHAT’S THE BIG IDEA?
Period
Technology
Strengths
Weaknesses
2002/03
ASP.NET Web Forms 1.0/1.1
Compiled
“Stateful” UI
Vast infrastructure
Heavy on bandwidth
Ugly HTML
Untestable
Encourages object-oriented
programming
2005
ASP.NET Web Forms 2.0
2007
ASP.NET AJAX
2008
ASP.NET Web Forms 3.5
2009
ASP.NET MVC 1.0
Discussed shortly
2010
ASP.NET MVC 2.0
ASP.NET Web Forms 4.0
2011
ASP.NET MVC 3.0
* CGI is a standard means of connecting a web server to an arbitrary executable program that returns dynamic
content. The specification is maintained by the National Center for Supercomputing Applications (NCSA).
Traditional ASP.NET Web Forms
ASP.NET was a huge shift when it first arrived in 2002. Figure 1-1 illustrates Microsoft’s technology stack as it
appeared then.
2
763853530.001.png 763853530.002.png
 
CHAPTER 1 n WHAT’S THE BIG IDEA?
Figure 1-1. The ASP.NET Web Forms technology stack
With Web Forms, Microsoft attempted to hide both HTTP (with its intrinsic statelessness) and HTML (which at
the time was unfamiliar to many developers) by modeling the user interface (UI) as a hierarchy of server-side control
objects. Each control kept track of its own state across requests (using the View State facility), rendering itself as
HTML when needed and automatically connecting client-side events (e.g., a button click) with the corresponding server-
side event handler code. In effect, Web Forms is a giant abstraction layer designed to deliver a classic event-driven GUI
over the Web.
The idea was to make web development feel just the same as Windows Forms development. Developers no
longer had to work with a series of independent HTTP requests and responses—we could now think in terms of a
stateful UI. We could forget about the Web and its stateless nature and instead build UIs using a drag-and-drop
designer and imagine, or at least pretend, that everything was happening on the server.
What’s Wrong with ASP.NET Web Forms?
Traditional ASP.NET Web Forms was a great idea, but reality proved more complicated. Over time, the use of Web
Forms in real-world projects highlighted some shortcomings:
View State weight : The actual mechanism for maintaining state across requests (known as
View State) results in large blocks of data being transferred between the client and server.
This data can reach hundreds of kilobytes in even modest web applications, and it goes back
and forth with every request, frustrating site visitors with slower response times and
increasing the bandwidth demands of the server.
Page life cycle : The mechanism for connecting client-side events with server-side event
handler code, part of the page life cycle, can be extraordinarily complicated and delicate.
Few developers have success manipulating the control hierarchy at runtime without getting
View State errors or finding that some event handlers mysteriously fail to execute.
3
763853530.003.png 763853530.004.png
Zgłoś jeśli naruszono regulamin