0% found this document useful (0 votes)
47 views

Contents:: Module Overview Overview of Microsoft Web Technologies Module Review and Takeaways

This document provides an overview of Module 1 which explores ASP.NET MVC 5. The module contains lessons on Microsoft web technologies, an overview of ASP.NET, and introductions to the MVC framework. The objectives are to understand ASP.NET's role in web development, the different ASP.NET programming models, and the distinctions between an MVC model, controller, and view.

Uploaded by

Pablo Ivaldi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Contents:: Module Overview Overview of Microsoft Web Technologies Module Review and Takeaways

This document provides an overview of Module 1 which explores ASP.NET MVC 5. The module contains lessons on Microsoft web technologies, an overview of ASP.NET, and introductions to the MVC framework. The objectives are to understand ASP.NET's role in web development, the different ASP.NET programming models, and the distinctions between an MVC model, controller, and view.

Uploaded by

Pablo Ivaldi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

1/9/2020 Module 1: Exploring ASP.

NET MVC 5

Module 1: Exploring ASP.NET MVC 5

Contents:

Module Overview

Lesson 1: Est Overview of Microsoft Web Technologies


ed
oc
um
Lesson N
2:o Overviewen of ASP.NET
es t
tán p art o pe
n r
Lesson 3: erm ers@ tento
pIntroduction
e ASP.NET MVC 5
itid ed ce a
as uc
Lab: Exploring ac DaMVC
lasASP.NET n 5
co ionit iel M
pia .co
ss m acha
Module Review and in Takeaways do
au .
tor
iza
ció
n.

Module Overview

Microsoft ASP.NET MVC 5 and the other web technologies of the .NET Framework help you create and host
Es
te
dynamic, powerful, do and extensible web applications. ASP.NET MVC 5 supports agile, test-driven development and
cu
the latestNweb me such as HTML 5. To build robust web applications, you need to be familiar with the
standards
oe nto
technologiessand pa
tán products pin
rtn e the Microsoft web stack. You also need to know how ASP.NET applications work with
pe ers rten
IIS, Visual Studio, SQLr mi Server,
@ ec
tid ed Microsoft
e Azure, and Microsoft Azure SQL Database to deliver engaging webpages
a u ca a Da language that best suits a set of business requirements, you need to
to site visitors. To chooses ala programming
s c cion niel
op (MVC) i Ma
know how Model-View-Controller ias t.comapplications
ch
differ from the other ASP.NET programming models: Web
Pages and Web Forms. sin ad
au o .
tor
iza
ció
The web application that you will design and develop n. in the labs throughout this course will help you develop web
applications that fulfill business needs.

Objectives
Es this module, you will be able to:
After completing
te
do
cu
No me
• Describeethe nto
stá rolepaof ASP.NET in the web technologies stack, and how to use ASP.NET to build web applications.
n p rtne perte
erm rs@ ne
ed ce amodels available in ASP.NET: Web Pages, Web Forms, and MVC—and select
• Describe the threeitprogramming
ida uc
sl ac Dan
an appropriate model forasacgiven ionproject.
iel
op i
ias t.com Mach
sin ad
• Distinguish between an MVC Model, o.
auan MVC Controller, and an MVC View.
tor
iza
ció
n.

Lesson 1: Overview of Microsoft Web Technologies

Before you use ASP.NET MVC 5, you need to know where Microsoft ASP.NET fits in the context of the entire
E
Microsoft websttechnologies
ed stack. You should know how ASP.NET websites are hosted in Internet Information
oc
Server (IIS)
No and u
Microsoft
m Azure, and how they run server-side code on web servers, and client-side code on web
en
e s
browsers, to help p t o
tán provide
ar rich
pe and compelling content.
pe tners rten
rm @ e
itid ed ce a
as uc
Lesson Objectiveslas c acion Danie
op i l
ias t.com Mach
After completing this lesson, you will be able to:

https://www.skillpipe.com/#/reader/book/4ed7876c-8864-4cf5-91ee-491726dfe322 1/25
1/9/2020 Module 1: Exploring ASP.NET MVC 5

• Provide an overview of Microsoft web technologies.

• Provide an overview of ASP.NET.

• Provide an overview of client-side web technologies, including AJAX and JavaScript libraries.

• Describe the role of IIS in the Microsoft web technologies stack.

• Describe the role of Microsoft Azure in the Microsoft web technologies stack.
Es
te
do
cu
No me
es nto
Introduction tán to pa Microsoftpe Web Technologies
rtn rt
pe e
rm rs@ enec
itid ed ea
as u
las caci Dani
co on e
pia it.co l Mac
ss m ha
in do
au .
tor
iza
ció
n.

Es
te
do
cu
No me
es nt
tán part o pe
pe n e rt
rm rs@ enec
itid ed ea
as u
las caci Dani
co on e
pia it.co l Mac
ss m ha
in do
au .
tor
iza
ció
n.

Microsoft provides
Es a broad range of technologies that you can use to create rich web applications and publish them
te
on intranets and dover
oc the Internet. Besides publishing web applications, you can use these technologies to develop
N um
and host websites,
oe whichen run code both on the web server and on the user’s web browser.
stá pa to
n p rtne perte
erm rs@ ne
Developer Tools itid ed ce a
as u
las caci Dani
co on e
p a it.co l Mac
You can create simple websites iwith s s textmand images ha by using a text editor, such as Notepad. However, most
in do
websites require complex actions to be performed a u .
on the server-side, such as database operations, email delivery,
tor
iz
complex calculations, or graphics rendering.aTo ció create such complex, highly functional, and engaging websites
n.
quickly and easily, Microsoft provides the Microsoft Visual Studio 2017 tool. You can use Visual Studio 2017, an
Integrated Development Environment (IDE), to create custom applications based on Microsoft technologies,
regardless of whether these applications run on the web, on desktops, on mobile devices, or by using Microsoft
cloud services. Visual Studio 2017 has rich facilities for designing, coding, and debugging any ASP.NET web
application, including MVC applications.
Es
te
do
cu
Hosting NTechnologies me
oe nto
stá pa
n p rtne perte
erm rs@ ne
Regardless of the toolitidyou ed tocbuild
e a a web application, you must use a web server to host the web application.
as use uc Da
When users visit your site, athe l a cio server ni responds by rendering HTML and returning it to the user’s browser for
s c host
op n it.c el Ma
display. The host server may query i a o
s a database
m chbefore it builds the HTML, and the host server may perform other
actions such as sending emails or saving uploaded files. When you finish building the web application and make it
ready for users to access on an intranet or over the Internet, you must use a fully functional web server such as:

https://www.skillpipe.com/#/reader/book/4ed7876c-8864-4cf5-91ee-491726dfe322 2/25
1/9/2020 Module 1: Exploring ASP.NET MVC 5

• Microsoft Internet Information Server. IIS is an advanced website hosting technology. You can install IIS servers
on your local network or perimeter network, or employ IIS servers hosted by an Internet service provider (ISP).
IIS can host any ASP.NET, PHP, or Node.js websites. You can scale up IIS to host large and busy websites by
configuring server farms that contain multiple IIS servers, all serving the same content.

• Microsoft Azure. Microsoft Azure is a cloud platform that provides on-demand services to build, deploy, host, and
manage web applications through Microsoft-managed data centers. When you use Microsoft Azure services,
you need to pay only for the data that your website serves. Also, you need not worry about building a scalable
Es
infrastructure
te because Microsoft Azure automatically adds resources as your website grows.
do
cu
No me
es nt
tán part o pe
pe n e s rten
rm a rdatabase e
Most websites require itid @ed cetoa manage data such as product details, user information, and discussion topics.
a
You can choose from thesfollowing u Da
las caci Microsoft technologies to manage your data:
co on niel
pia i t .c M
s s om acha
i n
• Microsoft SQL Server. SQL Server aisu a premium do database server that you can use to host any database from
.
tor
the simplest to the most complex. SQL Server iza can scale up to support very large databases and very large
ció
n.
numbers of users. You can build large SQL Server clusters to ensure the best availability and reliability. Many of
the world’s largest organizations rely on SQL Server to host data.

• Microsoft Azure SQL Database. SQL Database is a cloud database platform and a part of Microsoft Azure.
Using SQL Database, you can deploy your database and pay only for the data that you use. You need not worry
Es
about managing your database infrastructure because your database scales up automatically as your website
te
do
grows.N cum
oe en
stá pa to
n p rtne perte
erm rs@ ne
itid ed ce a
as u
Code Execution Technologies las caci Dani
co on e
pia it.co l Mac
ss m h
The code that you write in a developer in tool mustarun do in one of two locations:
au .
tor
iza
ció
n
• On the web server. This code has full access .to the power of the web server and any databases attached to it. It
can access the database quickly, send email messages, and render webpages.

• On the user’s web browser. This code responds quickly to user actions, such as mouse clicks, but it is more
limited in what it can accomplish without interacting with the web server.
Es
te
do
cu
No me
es nt
You need to use p art otechnologies
tán different pe to run server-side code and client-side code.
pe n e rt
rm rs@ enec
itid ed ea
a u
Server-Side Execution s las caci Dani
co on e
pia it.co l Mac
ss m ha
in do
Microsoft ASP.NET is a server-side web au environment . that runs server-side .NET code that you write in Visual
tor
Studio 2017. The code accesses the database, i za renders HTML pages, and returns them to the web browser. The
ció
MVC programming model is a part of ASP.NET.nOther . server-side technologies include PHP and Node.js.

Client-Side Execution

Most web browsers


Es can run code written in the JavaScript language. This code is sent to the browser as text within
t e
a rendered HTMLdopage or in a separate .js file. Because JavaScript is local to the browser, it can respond very
cu
quickly toNouser actions mesuch as clicking, pointing, or dragging.
es nt
tán p art o pe
pe n e rt
rm rs@ enec
Many JavaScript libraries itid are edavailable e a to accelerate client code development. For example, the popular jQuery
as uc D
library makes it simple to access las a cpage aelements
n and manipulate them by changing their style or content. When you
co ionit iel M
use such libraries, you can write piafunctions
.co in aacfew lines that would otherwise require hundreds of lines of your own
s m h
JavaScript code.

https://www.skillpipe.com/#/reader/book/4ed7876c-8864-4cf5-91ee-491726dfe322 3/25
1/9/2020 Module 1: Exploring ASP.NET MVC 5

ASP.NET applications can also use the Asynchronous JavaScript and XML (AJAX) technology on the client
computer. You can use AJAX to update a small section of an HTML page, instead of reloading the entire page from
the server. Such partial page updates help make webpages more responsive and engaging.

Question: If you want to animate a page element, for example, by fading it in, would you write server-side or client-
side code?

OverviewE of ASP.NET
ste
do
cu
No me
es nt
tán part o pe
pe n e rt
rm rs@ enec
itid ed ea
as u
las caci Dani
co on e
pia it.co l Mac
ss m ha
in do
au .
tor
iza
ció
n.

Es
te
do
cu
No me
es nt
tán part o pe
pe n e rt
rm rs@ enec
itid ed ea
as u
las caci Dani
co on e
pia it.co l Mac
ss m ha
in do
au .
tor
iza
ció
n.

You can use ASP.NET to develop database-driven, highly-functional, and scalable dynamic websites that use
client-side and server-side code. You can create many kinds of website with ASP.NET, for example, web portals,
online shopping sites, blogs, and wikis.
Es
te
do
Programming Models cu
me
No
es nt
tán p art o pe
pe n e rte
When you use ASP.NET rm rsto@build nean application, you are not restricted to a single style of programming; instead,
itid ed ce a
you can choose from three as different
uc programming models. Each programming model has a typical structure in the
las ac Dan
development environment and ion code
costores ie in different places in the web hierarchy:
pia it.co l M
ss m acha
in do
au .
• Web Pages: When you build a site bytousing riz Web Pages, you can write code by using the C# or Visual Basic
ac
programming language. If you write C# code, ión these pages have a .cshtml file extension. If you write Visual Basic
.
code, these pages have a .vbhtml file extension. ASP.NET runs the code in these pages on the server to render
data from a database, respond to a form post, or perform other actions. This programming model is simple and
easy to learn, and is suited for simple data-driven sites. ASP.NET includes Web Pages.

• Web Forms:Es When you build a site by using Web Forms, you employ a programming model with rich server-side
te
controls and adopage
cu life cycle that is not unlike building desktop applications. Built-in controls include buttons,
No me
text boxes,
es and grid nt
views for displaying tabulated data. You can also add third-party controls or build custom
tán p art o pe
pe
controls. To respond n r
ers user tenactions, you can attach event handlers containing code to the server-side controls.
rm to e
itid @ed ce a
For example, to respond as to uac click D on a button called firstButton, you could write code in the
ac
firstButton_Click() event
las ion aniel
chandler.
op i
ias t.com Mach
• MVC: When you build a site by using ASP.NET MVC, you separate server-side code into three parts:

https://www.skillpipe.com/#/reader/book/4ed7876c-8864-4cf5-91ee-491726dfe322 4/25
1/9/2020 Module 1: Exploring ASP.NET MVC 5

o Model. An MVC model defines a set of classes that represent the object types that the web application
manages. For example, the model for an ecommerce site might include a Product model class that defines
properties such as Description, Catalog Number, Price, and others. Models often include data access logic
that reads data from a database, and writes data to that database.

o Controllers. An MVC controller is a class that handles user interaction, creates and modifies model classes,
and selects appropriate views. For example, when a user requests full details about a particular product, the
controller creates a new instance of the Product model class and passes it to the Details view, which displays
it to theEsuser.
te
do
cu
No me
o Views.esAn MVC nt is a component that builds the webpages that make up the web application’s user
view
tán part o pe
pe
interface. Controllers n rt pass an instance of a model class to a view. The view displays properties of the
e often
rm rs@ enec
model class. For itidexample,
ed if ethe
a controller passes a Product object, the view might display the name of the
as u
las caci Dani
product, a picture, and the on
co price. e
pia it.co l Mac
ss m ha
in do
au .
tor
iza
This separation of model, view, and controllercicode ón ensures that MVC applications have a logical structure, even for
.
the most complex sites. It also improves the testability of the application. Ultimately, ASP.NET MVC enables more
control over the generated HTML than either Web Pages or Web Forms.

Additional Reading: In Lesson 2, Overview of ASP.NET, you will see how to choose the most appropriate
Es
te
programming model for a given website project.
do
cu
No me
es nt
tán part o pe
pe n e rt
The ASP.NET API rm rs@ enec
itid ed ea
as u
las caci Dani
on
Whichever programming model co you it.c el M you have access to classes from the ASP.NET API. These classes are
pia choose,
s s om acha
included in the .NET Framework in namespaces in within
do the System.Web namespace and can be used to rapidly
au .
implement common website functionalities tor such as:
iza
ció
n.
• Configuration. Using Web.config files, you can configure your web application, regardless of the programming
model. Web.config files are XML files with specific tags and attributes that the ASP.NET runtime accepts. For
example, you can configure database connections and custom error pages in the Web.config file. In code, you
can access the configuration through the System.Web.Configuration namespace.
Es
te
• Authenticationdoand
cu Authorization. Many websites require users to log on by entering a user name and password,
No me
or by providing
es extra ninformation.
t You can use ASP.NET membership providers to authenticate and authorize
tán p art o pe
n
pe access
users, and restrict ers rto tencontent. You can also build pages that enable users to register a new account,
rm e
itid @ed ce a
reset a password, recover as auclost password, or perform other account management tasks. Membership providers
las ac Dan
belong to the System.Web.Security co ionit namespace.
iel
M
pia .c
s s om acha
in do
• Caching. ASP.NET may take some atime uto to render . a complex webpage that may require multiple database
riz
queries or calls to external web services. You a ció can use caching to mitigate this delay. ASP.NET caches a
n.
rendered page in memory, so that it can return the same page to subsequent user requests without having to
render it again from the start. In a similar manner, .NET Framework objects can also be cached. You can access
cached pages by using the System.Runtime.Caching namespace and configure the caches in Web.config.

Es
te
Compiling ASP.NET do Code
cu
No me
es nt
tán p art o pe
n
pe server-side
e rt
Because ASP.NET rm rs@ encode ec
uses the .NET Framework, you must write code in a .NET managed
programming language i tid suchedas C# e aor Visual Basic. Before running the code, it must be compiled into native code
as uc
l ac Dan
so that the server CPU canasprocessco ionit. ie is a two-stage process:
This
pia it.co l Mac
s m h
1. Compilation to MSIL. When you build a website in Visual Studio, the ASP.NET compiler creates .dll files with

https://www.skillpipe.com/#/reader/book/4ed7876c-8864-4cf5-91ee-491726dfe322 5/25
1/9/2020 Module 1: Exploring ASP.NET MVC 5

all the code compiled into Microsoft Intermediate Language (MSIL). This code is both independent of the
language you used to write the application and the CPU architecture of the server.

2. Compilation to native code. When a page is requested for the first time, the Common Language Runtime
(CLR) compiles MSIL into native code for the server CPU.

This two-stage compilation process enables components written in different languages to work together and
E
enables manysterrors
ed to be detected at build time. Note, however, that pages may take extra time to render the first
oc
um after a server restart. To avoid this delay, you can pre-compile the website.
time theyNare requested
oe en
stá p to
n p artne perte
When you use theerdefault
mi rs@ ne
compilation model, delays can arise when the first user requests a page. This is because
tid ed ce a
a u
s l page D serving it to the browser. To avoid such delays and to protect source code,
ASP.NET must compile the as cacbefore
ion aniel
use pre-compilation. When you co pre-compile
i t Ma site, all the ASP.NET files, including controllers, views, and models,
pia .c
s s om acha
are compiled into a single .dll file. in do
au .
tor
iza
ció
n.
Additional Reading: For more information about ASP.NET compilation, see:
http://go.microsoft.com/fwlink/?LinkID=293680&clcid=0x409

Question: Which of the three programming models do you think provides the most control over the HTML and
Es
JavaScript code te that is sent to the browser?
do
cu
No me
es nto
pa
Client-Siden Web
t á
pe
rtn Technologies
e
pe
rt
rm rs@ enec
itid ed ea
as u
las caci Dani
co on e
pia it.co l Mac
ss m ha
in do
au .
tor
iza
ció
n.

Es
te
do
cu
No me
es nt
tán p art o pe
pe n e rt
rm rs@ enec
itid ed ea
as u
las caci Dani
co on e
pia it.co l Mac
ss m ha
in do
au .
tor
iza
ció
n.

Originally, inEASP.NET,
ste and similar technologies like PHP, all the code ran on the web server. This approach is often
practical becausedothe cu web server usually has immediate access to the database and more processor power and
N me
memory than o e a typical client
nto computer. However, in such an approach, every user action requires a round trip
stá pa
between the client n p andrtnthe pweber
erm ers@ tenserver, ec
and most actions require a complete reload of the page. This can take
i
significant time. To respondtid equickly
du e and
a D provide better user experience, you can supplement server-side code with
as
lasthecweb
ac browser.
a
client-side code that runs in co i on nie
pia it.co l Mac
s m h
JavaScript

https://www.skillpipe.com/#/reader/book/4ed7876c-8864-4cf5-91ee-491726dfe322 6/25
1/9/2020 Module 1: Exploring ASP.NET MVC 5

JavaScript is a simple scripting language that has syntax similar to C#, and it is supported by most web browsers. A
scripting language is not compiled. Instead, a script engine interprets the code at run time so that the web browser
can run the code.

Note: Besides JavaScript, Internet Explorer supports VBScript. There are other scripting languages also,
but JavaScript is supported by virtually every web browser. This is not true of any other scripting language.
Unless your target audience is very limited and you have control over the browser used by your users, you
should use JavaScript because of its almost universal support.
Es
te
do
cu
No me
es JavaScript nt
tán part o pecode in your ASP.NET pages, irrespective of the programming model you choose.
You can include
pe n e s rten
rm rlanguage,
JavaScript is a powerful e but can require many lines of code to achieve visual effects or call external
itid @ed ce a
a
services. Script libraries contain
sl u D JavaScript functions that help implement common actions that you might
pre-built
as cacio anie
want to perform on client-sidecocode. pia
nYou
i t .co canl M use a script library, instead of building all your own JavaScript code
s m acha
from the start; using a script library shelpsin reduce development
do time and effort.
au .
tor
iza
ció
Different browsers interpret JavaScript differently. n. When you develop an Internet site, you do not know what
browsers site visitors use. Therefore, you must write JavaScript that works around browser compatibility.

jQuery

E
jQuery is one sof
te the most popular JavaScript libraries. It provides elegant functions for interacting with the HTML
do
elementsNon your page cu and with cascading style sheet (CSS) styles. For example, you can locate all the <div>
me
oe nto
pa
elements on satáwebpage and change their background color by using a single line of code. To achieve the same
n p rtne perte
erm rs@
result by using JavaScript only,nyou
e need to write several lines of code and a programming loop. Furthermore, the
iti ed ce a
code you write may beddifferent
as
las
ucfor different
ac Dan browsers. Using jQuery, it is easier to write code to respond to user
c ion ijQuery
el
actions and to create simple animations.
op i also handles browser differences. You can use jQuery to call web
ias t.com Mach
services on remote computers and supdate in the a
webpage
do with the results returned.
au .
tor
iza
ció
The jQuery project also includes two other JavaScript n. libraries that extend the base jQuery library:

• jQuery UI. This library includes a set of widgets that you can use to help build a user interface. There are date
pickers, spinners, dialog boxes, autocomplete text boxes, and other widgets. You can also apply themes to your
jQuery UI widgets to integrate their colors and styles with the website branding.
Es
te
d
• jQuery Mobile. oThiscu library makes it easy to provide a user interface for mobile devices such as phones and
me
No
tablets. Itesrenders nto by using progressive enhancement. For example, using jQuery Mobile, you can display
tán p aHTML
rtn pe
rich, advancedpecontrols e onrtadvanced
en mobile devices such as smartphones with large screens, whereas you can
rm rs@ e
itid ed ce a
display a simpler UI with as theucsameDfunctionality for older mobile devices with smaller screens.
las ac an
co ionit iel M
pia .c
s s om acha
in do
au .
tor
Note: There are many other JavaScript i za libraries such as Prototype, Enyo, Ext, and Dojo Toolkit. If you find
ció
any of these better suited to a particularntask, . or if you have experience in developing web applications by
using them, you can include them in your ASP.NET pages, instead of jQuery.

AJAX
Es
te
do
AJAX is N
a technology cu that enables browsers to communicate with web servers asynchronously by using the
me
oe nto
XmlHttpRequest
stá object
pa without completely refreshing the page. You can use AJAX in a page to update a portion of
n p rtne perte
the page with newerdata,
mi without
r s@ nereloading the entire page. For example, you can use AJAX to obtain the latest
tid ed ce a
comments on a product,aswithout u refreshing the entire product page.
las caci Dani
co on e
pia it.co l Mac
s m h
AJAX is an abbreviation of Asynchronous JavaScript and XML. AJAX is implemented entirely in JavaScript, and
ASP.NET, by default, relies on the jQuery library to manage AJAX requests and responses. The code is run

https://www.skillpipe.com/#/reader/book/4ed7876c-8864-4cf5-91ee-491726dfe322 7/25
1/9/2020 Module 1: Exploring ASP.NET MVC 5

asynchronously, which means that the web browser does not freeze while it waits for an AJAX response from the
server. Initially, developers used XML to format the data returned from the server. More recently, however,
developers use JavaScript Object Notation (JSON) as an alternative format to XML.

Question: Can you think of any problems that might arise if you include the jQuery library with every page in your
application?

Internet Information
E Server
ste
do
cu
No me
es nt
tán part o pe
pe n e rt
rm rs@ enec
itid ed ea
as u
las caci Dani
co on e
pia it.co l Mac
ss m ha
in do
au .
tor
iza
ció
n.

Es
te
do
cu
No me
es nt
tán part o pe
pe n e rt
rm rs@ enec
itid ed ea
as u
las caci Dani
co on e
pia it.co l Mac
ss m ha
in do
au .
tor
iza
ció
n.

Every website must be hosted by a web server. A web server receives requests for web content from browsers,
runs any server-side code, and returns webpages, images, and other content. HTTP is used for communication
between the web browser and the web server.
Es
te
do
Internet Information cuServer is a web server that can scale up from a small website running on a single web server
me
No
to a large website
es running nt on a multiple web server farms. Internet Information Server is available with Windows
tán p art o pe
pe n e rt
Server. rm rs@ enec
itid ed ea
as u
las caci Dani
Internet Information ServercFeatures on el
op i
ias t.com Mach
sin ad
au o.
Internet Information Server is tightly integrated t o riz with ASP.NET, Visual Studio 2017, and Windows Server. It includes
ac
the following features: ión
.

• Deployment Protocols. The advanced Web Deploy protocol, which is built into Visual Studio 2017, automatically
manages the deployment of a website with all its dependencies. Alternatively, you can use File Transfer Protocol
(FTP) to deploy content.
Es
te
• Centralized Web do Farm Management. When you run a large website, you can configure a load-balanced farm of
cu
No me
many IISeservers nto to large sizes. IIS management tools make it easy to deploy sites to all servers in the
stá pato scale
n p rtne perte
farm and manage erm sitesrs afterndeployment.
e
itid @ed ce a
as uc Da
• High Performance Caches. las You ac can configure
n ASP.NET to make optimal use of the IIS caches to accelerate
co ionit iel M
responses to user requests. pWhen ias .IIS
co serves
m a ch page or other content, it can cache it in memory so that
a
subsequent identical requests can be served faster.

https://www.skillpipe.com/#/reader/book/4ed7876c-8864-4cf5-91ee-491726dfe322 8/25
1/9/2020 Module 1: Exploring ASP.NET MVC 5

• Authentication and Security. IIS supports most common standards for authentication, including Smart Card
authentication and Integrated Windows authentication. You can also use Secure Sockets Layer (SSL) to encrypt
security-sensitive communications, such as logon pages and pages containing credit card numbers.

• ASP.NET Support. IIS is a web server that fully supports ASP.NET.

• Other Server-Side Technologies. You can host websites developed in PHP and Node.js on IIS.

Es
te
Scaling Up IIS docu
No me
es nt
tán part o pe
n
pe haserlimited rt
A single web server rm s@ enscalability
e because it is limited by its processor speed, memory, disk speed, and
itid
other factors. Furthermore, ed ceweb a D servers are vulnerable to hardware failures and outages. For example, when
as single uc
ac
a single web server is offline,
las
cyour ion aniel is unavailable to users.
op website
i
ias t.com Mach
sin ad
au o.
You can improve the scalability and resilience t ori of your website by hosting it on a multiple server farm. In such server
za
farms, many servers share the same server name. ció Therefore, all servers can respond to browser requests. A load
n.
balancing system such as Windows Network Load Balancing or a hardware-based system such as Riverbed
Cascade, distributes requests evenly among the servers in the server farm. If a server fails, other servers are
available to respond to requests, and thereby, the website availability is not interrupted. IIS servers are designed to
work in such server farms and include advanced management tools for deploying sites and managing member
servers. Es
te
do
cu
No me
Perimeter Networks
es nt
tán part o pe
pe n e rt
rm rs@ enec
itid ed often e a located on a perimeter network. A perimeter network has a network segment
Web servers, including IIS,
as are u
las caci Dani
that is protected from the Internet on
co through ea firewall that validates and permits incoming HTTP requests. A second
pia it.co l Mac
firewall, which permits requests only s s from m the web ha server, separates the perimeter network from the internal
in do
organizational network. Supporting servers, a uto such as. database servers, are usually located on the internal
riz
organizational network. ac
ión
.

In this configuration, Internet users can reach the IIS server to request pages and the IIS server can reach the
database server to run queries. However, Internet users cannot access the database server or any other internal
computer directly. This prevents malicious users from running attacks and ensures a high level of security.
Es
te
IIS Express do
cu
No me
e nto
stá pa
n p rtne perte
Internet Information ermServerrs Express
ne does not provide all the features of Internet Information Server on Windows
itid @ed ce a
Server. For example, you as cannot
u create load-balanced server farms by using Internet Information Server Express.
las caci Dani
However, it has all the features on
co necessary e to host rich ASP.NET websites and other websites on a single server.
pia it.co l Mac
ss m ha
in do
au .
Other Web Servers tor
iza
ció
n.
Apache is a popular non-Microsoft web server and there are other alternatives such as nginx. Apache can be
installed on Windows Server or Windows client computers to host websites during development or for production
deployments.

Question: IfEyou
ste wanted to host an ASP.NET site you had written for simple testing by a small team of developers,
do
which of the precedingcu web servers would you use as a host?
No me
es nt
tán p art o pe
pe n e rt
Microsoft Azure rm rs@ enec
itid ed ea
as u
las caci Dani
co on e
pia it.co l Mac
s m h

https://www.skillpipe.com/#/reader/book/4ed7876c-8864-4cf5-91ee-491726dfe322 9/25
1/9/2020 Module 1: Exploring ASP.NET MVC 5

Es
te
do
cu
No me
es nt
tán part o pe
pe n e rt
rm rs@ enec
itid ed ea
as u
las caci Dani
co on e
pia it.co l Mac
ss m ha
in do
au .
tor
iza
ció
n.

Es
te
do
c
MicrosoftNAzure
oe
is aupart
me of Microsoft cloud services for hosting business-critical systems. When you run code on
nto
stá the
Microsoft Azure, pacode
n p rtne runs pe on servers at Microsoft-managed data centers at locations around the globe. You
rte
erm rs@when
have two main advantages ne you use Microsoft Azure to host and deploy your web application:
itid ed ce a
as uc
las ac Dan
co ionit iel M
• Flexible Scaling: As the needs pia of your
.c web application and database grow, extra server resources are
s s om acha
automatically allocated. You do not in need to plan do for server farms or load balancing systems because these are
au .
tor
built into Microsoft Azure. iza
ció
n.
• Flexible Pricing: With Microsoft Azure, you can choose a pay-as-you-go pricing model, which means that you
only pay for the data that you use. This makes Microsoft Azure very cost-efficient for small websites. It also
makes costs predictable for large websites.

Es
te
do
You can N
use Microsoft cu Azure to host the following:
me
oe nto
stá pa
n p rtne perte
e m rs@ ne
• Web Apps. You rcan itidhost ean entire
c website on Microsoft Azure. Microsoft Azure supports websites developed in
as du e a D
ASP.NET, PHP, or Node.js. ca can aalso deploy websites to Microsoft Azure directly from Visual Studio 2017.
las You c n
co ionit iel M
pia .co ac
• API Apps. An API app does nots include sin m a user ha interface like a Web app. Instead, it consists of a set of methods
do
au .
that you can call, from other software.toYou riz can call API apps from mobile devices, desktop applications, and
ac
from website code running on the client-side iónor the server-side.
.

• Databases. When you use Internet Information Server to host a website, you can use SQL Server to store the
website database. When you host a website in Microsoft Azure, you can use SQL Database, which is a cloud-
based database service based on SQL Server, to host your database.
Es
te You can provision entire virtual servers in Microsoft Azure to run business-critical back office
• Virtual servers.do
cu
software
No or use the mevirtual servers as test environments. Virtual servers in Microsoft Azure can run Windows
es nt
tán
Server or Linux.
p art o pe
pe n e rt
rm rs@ enec
itid ed ea
• Mobile services. If you as develop
u
las caciapps Da for mobile devices such as phones and tablets, you can use Microsoft
c on niel
Azure to host services that ounderpinpia it.cothem.
M Such services can provide user preference storage, data storage and
s m ach
other functions.

• Media services. When you use Microsoft Azure to host media such as audio and video, it is automatically
https://www.skillpipe.com/#/reader/book/4ed7876c-8864-4cf5-91ee-491726dfe322 10/25
1/9/2020 Module 1: Exploring ASP.NET MVC 5

available to many types of devices such as computers, mobile phones, and tablets, and it is encoded in various
formats, such as MP4 and Windows Media formats.

Question: How would site visitors know if your site is hosted in Microsoft Azure or IIS Server?

Lesson 2: Overview of ASP.NET


Es
te
do
c
ASP.NETNohelps youucreate
me
nt
dynamic websites that use client-side and server-side code. In addition, with ASP.NET,
es
tán partto ao single
you are not restricted pe
pe ne rte style of programming; instead, you can choose from three different programming
models: Web Pages, r miWeb@ r s ne
tid Forms, ed ceand aD
MVC. These programming models differ from each other, and they have
their own advantages and a u
s ldisadvantages
c
as a cio a niein different scenarios. ASP.NET also provides many features that you can
c n
use, regardless of the programming o pia model i t .c l you M choose.
s s om acha
in do
au .
tor
Lesson Objectives i za ció
n.
After completing this lesson, you will be able to:

• Describe the Web Pages programming model.

• Describe Ethe
ste Web Forms programming model.
do
cu
No the MVC
• Describe mprogramming
en model.
es t
tán part o pe
pe ne rte
• Determine whether rm torsbuild
@ ne Pages, Web Forms, or MVC web applications, based on customer needs.
Web
itid ed ce a
as uc
las ac Dan
• Describe the features that ccan io ielin all ASP.NET applications, regardless of the chosen programming
op beniused
ias t.com Mach
model. sin ad
au o.
tor
iza
ció
n.
Web Pages Applications

Es
te
do
cu
No me
es nt
tán p art o pe
pe n e rt
rm rs@ enec
itid ed ea
as u
las caci Dani
co on e
pia it.co l Mac
ss m ha
in do
au .
tor
iza
ció
n.

Es
te
do
cu
No me
es nt
tán p art o pe
pe n e rt
rm rs@ enec
itid ed ea
as u
las caci Dani
co on e
pia it.co l Mac
s m h
Web Pages is the simplest programming model you can choose to build a web application in ASP.NET. You can
use Web Pages to create a website quickly and with little technical knowledge. There is a single file associated with

https://www.skillpipe.com/#/reader/book/4ed7876c-8864-4cf5-91ee-491726dfe322 11/25
1/9/2020 Module 1: Exploring ASP.NET MVC 5

each webpage that users can request. For each page, you write HTML, client-side code, and server-side code in
the same .cshtml file. The @ symbol is used to distinguish server-side code from HTML and JavaScript. When
users request the page, the ASP.NET runtime compiles and runs the server-side code to render HTML and returns
that HTML to the web browser for display.

Note: If you want to write server-side code in Visual Basic, you use .vbhtml files, instead of .cshtml files.

Es
te
do
You can use Visual cuStudio 2017 to create Web Pages applications.
me
No
es nt
tán part o pe
n
pe Example e rt
A Web Pages Code rm rs@ enec
itid ed ea
as u
las caci Dani
co on e
pia it.co l Mac
<h2>Special Offers</h2> s sin m ha
do
au .
<p>Get the best possible value on tor Northwind specialty foods by taking advantage of these
iza
ció
offers:</p> n.
@foreach (var item in offers) {
<div class="offer-card">
<div class="offer-picture">
@if (!String.IsNullOrEmpty(item.PhotoUrl)){
Es
te
<img src="@Href(item.PhotoUrl) alt="@item.Title" />
doc
No um
} en
es p to
</div>
t á a
n p rtne perte
erm rs@ ne
</div> itid ed ce a
as u
las caci Dani
} co on e
pia it.co l Mac
ss m ha
in do
au .
tor
The Web Pages programming model has thecfollowing i za advantages:
ión
.

• It is simple to learn.

• It provides precise control over the rendered HTML.

Es
te
do
c
No Pagesusite
Using a Web me has some disadvantages:
es nt
tán p art o pe
pe n e rt
rm rs@ enec
• It provides no controli tid overedURLs e athat appear in the Address bar.
as u
las caci Dani
on
co numbers el
• Large websites require large pia it.co of Mpages, each of which must be coded individually.
ss m acha
in do
au .
• There is no separation of business logic, tor input logic, and the user interface.
iza
ció
n.

Question: Why should web developers need to take control of the URLs that appear in the Address bar when a
visitor browses a Web Pages site?

Es
Web Formste Applications
d oc
No um
en
es t
tán p art o pe
pe ne rte
rm r s ne
itid @ed ce a
as uc
las ac Dan
co ionit iel M
pia .co
s m ach

https://www.skillpipe.com/#/reader/book/4ed7876c-8864-4cf5-91ee-491726dfe322 12/25
1/9/2020 Module 1: Exploring ASP.NET MVC 5

Es
te
do
cu
No me
es nt
tán part o pe
pe n e rt
rm rs@ enec
itid ed ea
as u
las caci Dani
co on e
pia it.co l Mac
ss m ha
in do
au .
tor
iza
ció
n.

Es
te
do
cu
Web FormsNo is another meprogramming model that you can choose in ASP.NET. A Web Forms application is
e nto
characterizedstáby pa
n p rtne which
controls, pe
rt
you can drag from the Visual Studio toolbox onto each webpage. This method of
s@ enec the method used in desktop applications.
erm rresembles
creating a user interfaceitid ed ea
as u
las caci Dani
co on e
Web Forms Controls pia it.co l Mac
ss m ha
in do
au .
tor
ASP.NET provides a wide variety of highly-functional iza controls that you assemble on Web Forms. After you add a
ció
control to a page, you can write code to respondn.to user events. For example, you can use code in a button click
event to process a user’s input in a form. The controls provided include:

• Input controls, such as text boxes, option buttons, and check boxes.

Es
• Display controls, such as image boxes, image maps, and ad rotators.
te
do
cu
No me
• Data display
es controls, nt such as grid views, form views, and charts.
tán p art o pe
pe n ers rten
rm which ec data entered by the user.
• Validation controls, itid @echeckdu e a D
as
las caci a
on niel
co menus
• Navigation controls, such as pia i t .c and M tree views.
s s om acha
in do
au .
tor
iza
ció
You can also create your own custom controls to n. encapsulate custom functionality.

Web Forms Code Files

In a Web Forms application, HTML and control markup is stored in files with an .aspx extension. Server-side C#
Es
code is usuallytewritten
do in an associated .cs file called a code-behind file. For example, a page called Default.aspx
cu
usually has m
No a code-behind en file called Default.aspx.cs.
es t
tán part o pe
pe ne rt
Similarly, when yourmwrite
r s@ eneccontrols, you store HTML and control markup in an .ascx file. A control called
itid custom
ed ea
a uc
CustomControl.ascx hassalacode-behind ac Danfile called CustomControl.ascx.cs.
sc ion iel
op i
ias t.com Mach
Web Forms applications can also contain class files that have the .cs extension.

https://www.skillpipe.com/#/reader/book/4ed7876c-8864-4cf5-91ee-491726dfe322 13/25
1/9/2020 Module 1: Exploring ASP.NET MVC 5

Note: If you write server-side code in Visual Basic, code-behind files have a .vb extension, instead of a .cs
extension.

Binding Controls to Data

In Web Forms applications, you can easily display data by binding controls to data sources. This technique
removes the necessity to loop through data rows and build displays line-by-line. For example, to bind a grid view
Es Server database table, you drag a SQL data source control onto the Web Form, and use a dialog
control to a SQLte
do
to bind the grid view cuto the data source. When the page is requested, ASP.NET runs the query on the data source
No me
and mergesesthe ntorows of data with the Web Forms page.
tán returned
pa
rtn pe
pe e rt
rm rs@ enec
itid ed ea
Advantages and Disadvantages as u
las caci of D Weba Forms
co on niel
pia i t .c M
s s om acha
The Web Forms programming modelinhas do
au the following .
advantages:
tor
iza
ció
• You can design your page visually by using server n. controls and Design View.

• You can use a broad range of highly functional controls that encapsulate a lot of functionality.

• You can display data without writing many lines of server-side code.
Es
te
• The user interface
do in the .aspx file is separated from input and business logic in the code-behind files.
cu
No me
es nt
tán part o pe
pe n ers rten
Using a Web Formsrmsiteitid has@ some e
ed cedisadvantages:
as uc a
las ac Dan
co ionit iel M
pia life.ccycle ac an abstraction layer over HTTP and can behave in unexpected
• The ASP.NET Web Forms page s s om is ha
in do
ways. You must have a complete understanding au .of this life cycle, to write code in the correct event handlers.
tor
iza
ció
• You do not have precise control over markupngenerated . by server-side controls.

• Controls can add large amounts of markup and state information to the rendered HTML page. This increases
the time taken to load pages.

Es
te
do
Question: Why shouldcu web developers be concerned about the markup and state information that ASP.NET Web
No me
es addpto anrendered
Forms controls to HTML page?
tán ar pe
pe tners rten
rm e
itid @ed ce a
a
MVC Applicationss las caci Dan u
co on ie
pia it.co l Mac
ss m ha
in do
au .
tor
iza
ció
n.

Es
te
do
cu
No me
es nt
tán p art o pe
pe n e rt
rm rs@ enec
itid ed ea
as u
las caci Dani
co on e
pia it.co l Mac
s m h

https://www.skillpipe.com/#/reader/book/4ed7876c-8864-4cf5-91ee-491726dfe322 14/25
1/9/2020 Module 1: Exploring ASP.NET MVC 5

Es
te
do
cu
No me
es nt
tán part o pe
pe n e rt
rm rs@ enec
itid ed ea
as u
las caci Dani
co on e
pia it.co l Mac
ss m ha
in do
au .
tor
iza
ció
n.

Es
te
do
cu
MVC is another
No me
programming model available in ASP.NET. MVC applications are characterized by a strong
e nto
án partnlogic,
separation ofstbusiness pe data access code, and the user interface into Models, Controllers, and Views.
rt
pe e
rm rs@ enec
itid ed ea
as u
Models las caci Dani
co on e
pia it.co l Mac
ss m ha
in d
Each website presents information about au different okinds
. of objects to site visitors. For example, a publisher’s
tor
website may present information about books iza and authors. A book includes properties such as the title, a summary,
ció
and the number of pages. An author may have properties n. such as a first name, a last name, and a short biography.
Each book is linked to one or more authors.

When you write an MVC website for a publisher, you would create a model with a class for books and a class for
authors. These model classes would include the properties described and may include methods such as “buy this
Es
te this author”. If books and authors are stored in a database, the model can include data access
book” or “contact do
code thatNcan readcand um change records.
en
oe to
stá pa
n p rtne perte
erm rs@ ne
Models are custom .NET itid classes
ed cande a store code in .cs files.
as u
las caci Dani
co on e
Views pia it.co l Mac
ss m ha
in do
au .
tor
Each website must render HTML pages that i zaa browser can display. This rendering is completed by Views. For
ció
n.
example, in the publishing site, a View may retrieve data from the Book Model and render it on a webpage so that
the user can see the full details. In MVC applications, Views create the user interface.

Views are markup pages that store both HTML and C# code in .cshtml files. This means that they are like Web
Pages, but they include only user interface code. Other logic is separated into Models and Controllers.
Es
te
do
cu
No
Controllers me
es nt
tán p art o pe
pe n e rt
rm rs@ enec
i
Each website must interact tid ed users e a when they click buttons and links. Controllers respond to user actions, load
as with uc Da
data from a model, and pass l a
as it to caioview, n e that it will render a webpage. For example, in the publishing site, when
co nit iso lM
pia . c o ac to see full details of that book. The Book Controller receives the
the user double-clicks a book, he sor she mexpects h
user request, loads the book model with the right book ID, and passes it to the Book Details View, which renders a
webpage that displays the book. Controllers implement input logic and tie Models to the right Views.

https://www.skillpipe.com/#/reader/book/4ed7876c-8864-4cf5-91ee-491726dfe322 15/25
1/9/2020 Module 1: Exploring ASP.NET MVC 5

Controllers are .NET classes that inherit from the System.Web.Mvc.Controller class and store code in .cs files.

Advantages and Disadvantages of MVC

The MVC programming model has the following advantages:

• Views enable the developer to take precise control of the HTML that is rendered.
Es
• You can usetethe
do Routing Engine to take precise control of URLs.
cu
No me
• Businesseslogic, nto
tán input
pa logic,
rtn pe and user interface logic are separated into Models, Controllers, and Views.
pe ers rten
rm ec
itid @
• Unit testing techniques ed Test e Driven
as and uc a Development (TDD) are possible.
las ac Dan
co ionit iel M
pia .c
s s om acha
in do
au .
Using an MVC site has some disadvantages: tor
iza
ció
n.
• MVC is potentially more complex to understand than Web Pages or Web Forms.

• MVC forces you to separate your concerns (models, views, and controllers). Some programmers may find this
challenging.
E
• You cannotstvisually
ed create a user interface by dragging controls onto a page.
oc
No u me
• You musteshave nunderstanding
to
tán apafull
rtn pe of HTML, CSS, and JavaScript to develop Views.
pe ers rten
rm e
itid @ed ce a
as uc
las ac Dan
ion
co a request iel
Question: When a user makes pia it.co for M a particular product in your product catalog, which component
ss m acha
receives the request first: a model, aincontroller, ordoa view?
au .
tor
iza
ció
Discussion: ASP.NET Application n.Scenarios

Es
te
do
cu
No me
es nt
tán p art o pe
pe n e rt
rm rs@ enec
itid ed ea
as u
las caci Dani
co on e
pia it.co l Mac
ss m ha
in do
au .
tor
iza
ció
n.

Es
te
do
cu
No me
es nt
tán p art o pe
pe n e rt
rm rs@ enec
itid ed ea
as u
las caci Dani
on
co
p it.c el Ma
The following scenarios describeiasome s orequirements
m ch for websites. In each case, discuss which programming model
you would choose to implement the required functionality.

https://www.skillpipe.com/#/reader/book/4ed7876c-8864-4cf5-91ee-491726dfe322 16/25
1/9/2020 Module 1: Exploring ASP.NET MVC 5

Database Front-End

Your organization has its own customer relationship management system that stores data in a SQL Server
database. Your team of developers wrote the user interface in Visual Studio 2017 as a desktop application. The
directors now require that all computers should be able to access the application even when the desktop client
application is not installed. Because all computers have a browser, you have decided to write a web application in
ASP.NET to enable this.

Es
E-Commerce tSite ed
oc
No um
en
es p to
tán
You are a consultant arfor pe software organization. You have been asked to architect an e-commerce website
pe t n eras large
rte
ne
r mi
that will enable customers @ to ce the entire catalog of software packages, download the packages, and
tid edbrowse aD
as uc
purchase licenses. The company las a chas aanlarge team of developers who are familiar with .NET object-oriented
co ionit iel M
programming. The company policy pia is .toc
s s ousem Test ac Driven Development for all software.
ha
in do
au .
tor
Website for a Small Charitable Trust iza
ció
n.

Your friend works for a charitable organization and asks your advice about a website. Your friend does not have any
budget to engage a consultant, but has created websites by using Microsoft FrontPage. Your friend wants to
include a database of merchandise that site visitors can browse and purchase.

Es
ed t
Shared ASP.NET
oc
u
Features
No me
es nto
tán pa pe
rtn rt
pe e
rm rs@ enec
itid ed ea
as u
las caci Dani
co on e
pia it.co l Mac
ss m ha
in do
au .
tor
iza
ció
n.

Es
te
do
cu
No me
es nt
tán p art o pe
pe n e rt
rm rs@ enec
itid ed ea
as u
las caci Dani
co on e
pia it.co l Mac
ss m ha
in do
au .
tor
iza
ció
n.

ASP.NET also includes a range of features that are available regardless of the programming model that you use.
This means that if you are familiar with these features from working with Web Pages or Web Forms, your
knowledge canEs be used in MVC applications also.
te
do
cu
No me
es nt
Configuration tán p art o pe
pe n e rt
rm rs@ enec
itid ed ea
When you configure an aASP.NET sl
as
uc site,
a D
cio ayou nie can control how errors are handled, how the site connects to databases,
how user input is validated, and c op manyn lM
it.cother
ias om settings.
ac
h
You can configure ASP.NET sites by creating and editing
Web.config files. The Web.config file in the root folder of your site configures the entire site, but you can override
this configuration at lower levels by creating Web.config files in sub-folders.

https://www.skillpipe.com/#/reader/book/4ed7876c-8864-4cf5-91ee-491726dfe322 17/25
1/9/2020 Module 1: Exploring ASP.NET MVC 5

An Example Web.config File

<?xml version="1.0" encoding="utf-8"?>


<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
<add key="webpages:Version"
E value="2.0.0.0" />
ste
do
<add key="webpages:Enabled" value="false" />
cum
oeN en
<add key="PreserveLoginUrl"
to value="true" />
stápa
n p rtne perte
<add key="ClientValidationEnabled" value="true" />
erm rs@ ne
itid e ce
as du
<add key="UnobtrusiveJavaScriptEnabled" a value="true" />
las caci Dani
</appSettings> c o ni e l
op
ias t.com Mach
<connectionStrings> sin ad
au o.
<add name="ApplicationServices" oriz t
ac
connectionString="Data Source=
ión
.
.\SQLEXPRESS;Integrated Security=SSPI;
AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient"/>
</connectionStrings>
Es
te
<system.web> d oc
No me u
<customErrors mode="RemoteOnly"
n defaultRedirect="~/Error.html" />
es t
tán p art o pe
<authentication ne
pe mode="Forms"> rt
rm rs@ enec
itid ed
<forms loginUrl="~/Account/Login" ea timeout="2880">
as uc
la ac Dan
</forms> s co ionit iel M
pia .c
</authentication> s s om acha
in do
au .
<pages> tor
iza
<namespaces> ció
n.
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
steE
<add namespace="System.Web.Routing" />
do
um c
<add namespace="System.Web.WebPages" />
N oe en
stá pa op t
<add namespace="System.Web.Optimization"/>
n rt e
pe ne rte
r ne
</namespaces> rmit s@e c
ida du e a D
s l c a an
</pages> as ci i on
co
pia it.c el M
</system.web> s s om acha
in do
</configuration> au .
tor
iza
ció
n.

If you need to access configuration values at runtime in your server-side .NET code, you can use the
System.Web.Configuration namespace.

Authentication
Es
te
d oc
No um
Many websites identify eusers
nto through authentication. This is usually done by requesting and checking credentials
es p
t á
such as a user nname a r p ert
pe and tne password,
rs en
although authentication can be done by using more sophisticated methods,
rmcards. ecsites require all users to authenticate before they can access any page, but it is
such as using smart itid @Some ed e a
as u
common to enable anonymous ac Dato
las caccess
co i on niesome lM
pages and require authentication only for sensitive or subscription
content. p i t . co
ias m ach

https://www.skillpipe.com/#/reader/book/4ed7876c-8864-4cf5-91ee-491726dfe322 18/25
1/9/2020 Module 1: Exploring ASP.NET MVC 5

ASP.NET supports several mechanisms for authentication. For example, if you are using Internet Explorer on a
Windows computer, ASP.NET may be able to use Integrated Windows authentication. In this mechanism, your
Windows user account is used to identify you. When you build Internet sites, you cannot be sure that users have
Windows, a compatible browser, or an accessible account, so Forms Authentication is often used. Forms
Authentication is supported by many browsers and it can be configured to check credentials against a database,
directory service, or other user account stores.

Membership and Roles


Es
te
do
cu
In many NInternet sites,mefor example, Facebook and Twitter, users can create their own accounts and set credentials.
oe no
stá yourpasite tcan
In this manner, n p rtne persupport ten
a large number of members without requiring a huge amount of administrative
e r
effort because administrators
mi r s @ do note create accounts.
tid ed ce a
as uc Da
las a c n
co ionit iel M
In ASP.NET, a membership provider pia is.ca
s s omcomponent ac
ha
that implements user account management features. Several
membership providers are supported by i n d o
au ASP.NET, such . as the SQL Membership Provider, which uses a SQL
to
database to store user accounts. You can ralso iza create a custom membership provider, inheriting from one of the
ció
default providers, if you have unique requirements. n.

When you have more than a few users, you may want to group them into roles with different levels of access. For
example, you might create a “Gold Members” role containing user accounts with access to the best special offers.
ASP.NET role providers enable you to create and populate roles with the minimum of custom code.
Es
te
do
cu
You can N
enable accessme to pages on your website for individual user accounts or for all members of a role. This
oe nto
stá as paauthorization.
process is knownn p rtne perte
erm rs@ ne
itid ed ce a
as u
State Management las caci Dani
co on e
pia it.co l Mac
ss m ha
in do
Web servers and web browsers communicate au through . HTTP. This is a stateless protocol in which each request is
tor
separate from requests before and after it. izAny ac values from previous requests are not automatically remembered.
ión
.
However, when you build a web application, you must frequently preserve values across multiple page requests.
For example, if a user places a product in a shopping cart, and then clicks “Check Out”, this is a separate web
request, but the server must preserve the contents of that shopping cart; otherwise, the shopping cart will be
emptied and the customer will buy nothing. ASP.NET provides several locations where you can store such values
Es
te
or state informationdo across multiple requests.
cu
No me
es nt
Caching tán p art o pe
pe n e rt
rm rs@ enec
itid ed ea
as uc Da
las
An ASP.NET page is built dynamically a c by
n the ASP.NET runtime on the web server. For example, in a Web Pages
co ionit iel M
pia .cthe
application, the runtime must execute ss o m C#acodech in the page to render HTML to return it to the browser. That C#
ad
in o.
code may perform complex and time-consuming au operations. It may run multiple queries against a database or call
tor
services on remote servers. You can mitigate i za these time delays by using ASP.NET caches.
ció
n.

For example, you can use the ASP.NET page cache to store the rendered version of a commonly requested page
in the memory of the web server. The front page of your product catalog may be requested hundreds or thousands
of times a day by many users. If you cache the page in memory the first time it is rendered, the web server can
serve it to most users very rapidly, without querying the database server and building the page from scratch.
Es
te
do
c
Question: No Can you uthink
me of other facilities that all ASP.NET applications might need, regardless of the
es nto
p
programming tmodel
án
pe
athey
rtn use? pe
rt
e
rm rs@ enec
itid ed ea
as u
las caci Dani
Lesson 3: Introduction co onto ASP.NET
e
pia it.co l Mac
MVC 5
s m h

https://www.skillpipe.com/#/reader/book/4ed7876c-8864-4cf5-91ee-491726dfe322 19/25
1/9/2020 Module 1: Exploring ASP.NET MVC 5

You need to know how models, views, and controllers work together to render HTML, and how the structure of MVC
applications determines the display of information in a Visual Studio 2017 project. You can examine the new
features of MVC 5, included in ASP.NET, to build rich and engaging applications.

Lesson Objectives
After completing this lesson, you will be able to:

Es
te
• Describe models,
do views, and controllers.
cu
No me
nt
es mainp features
• Explore thetán art o pe of an ASP.NET MVC 5 web application in Visual Studio.
pe n e rt
rm rs@ enec
itid ed ea
as u
las caci Dani
co on e
Models, Views, and Controllers pia it.co l Mac
ss m ha
in do
au .
tor
iza
ció
n.

Es
te
do
cu
No me
es nt
tán part o pe
pe n e rt
rm rs@ enec
itid ed ea
as u
las caci Dani
co on e
pia it.co l Mac
ss m ha
in do
au .
tor
iza
ció
n.

Es
te
do
cu
No me
es nt
tán p art o pe
Models represent data
pe nand
e thert accompanying business logic, controllers interact with user requests and implement
rm rs@ enec
i
input logic, and viewstibuild
da theed user e ainterface. By examining how a user request is processed by ASP.NET MVC 5,
sl uc Da
a
as dataciflows
you can understand how the on nthrough
i models, views, and controllers before being sent back to the
co
p it.c el Ma
browser. i a ss o m ch
in ad
au o.
tor
iza
Models and Data ció
n.

A model is a set of .NET class that represents objects handled by your website. For example, the model for an e-
commerce application may include a Product model class with properties such as Product ID, Part Number,
Catalog Number, Name, Description, and Price. Like any .NET class, model classes can include a constructor,
which is a procedure
Es that runs when a new instance of that class is created. You can also include other procedures,
te
if necessary. These do procedures encapsulate the business logic. For example, you can write a Publish procedure
cu
No the Product
that marks meas ready-to-sell.
es nt
tán p art o pe
pe n e rt
rm rs@ enec
i
Most websites store information
tid ed ineaadatabase. In an MVC application, the model includes code that reads and
as u Da
writes database records. ASP.NET las cacioMVC n works with many different data access frameworks. However, the most
co nit iel M
pia Entity
.coFramework.
commonly used framework is the s m ach

Controllers and Actions

https://www.skillpipe.com/#/reader/book/4ed7876c-8864-4cf5-91ee-491726dfe322 20/25
1/9/2020 Module 1: Exploring ASP.NET MVC 5

A controller is a .NET class that responds to web browser requests in an MVC application. There is usually one
controller class for each model class. Controllers include actions, which are methods that run in response to a user
request. For example, the Product Controller may include a Purchase action that runs when the user clicks the
Add To Cart button in your web application.

Controllers inherit from the System.Web.Mvc.Controller base class. Actions usually return a
System.Web.Mvc.ActionResult object.

Es
Views and Razor te
do
cu
No me
es nto
t á pa pe or .vbhtml file that includes both HTML markup and programming code. A view
n p ratn.cshtml
A view is, by default, r
erm ers@ tene
engine interprets viewitidfiles, eruns ce server-side code, and renders HTML to the web browser. Razor is the default
as du the a
view engine in ASP.NET MVC las 5. ci Dani
c a
co on e
pia it.co l Mac
ss m ha
in do
Part of a Razor View au .
tor
iza
ció
n.

<h2>Details</h2>

<fieldset>
<legend>Comment</legend>
E ste
do
cu
No en m
es to
<div class="display-label">
p
tán art pe
pe ne rte
@Html.DisplayNameFor(model => model.Subject)
r rs
mi n @ ec
ea
tid ed
</div> as uc
ac Dan las
co ionit iel M
<div class="display-field">
pia .c
s s om acha
@Html.DisplayFor(model in => model.Subject) do
au .
tor
</div> iza
ció
n.
<div class="display-label">
@Html.DisplayNameFor(model => model.Body)
</div>
<div class="display-field">
Es
te
do
@Html.DisplayFor(model => model.Body)
cu
</div> No me
es nt
t p art o pe
</fieldset>án p ne r
erm rs@ tene
itid ed ce a
as u
las caci Dani
co on el
pia ofit.acomodelM
Often, the view displays properties ss m acclass. ha In the preceding code example, the Subject property and
Body property are incorporated into the i n d o
au page. .
tor
iza
ció
n.
Request Life Cycle

The Request life cycle comprises a series of events that happen when a web request is processed. The following
steps illustrate the process that MVC applications follow to respond to a typical user request. The request is for the
details of a product
Es with the ID “1”:
te
do
cu
N me
1. The ouser es requests nthe
t web address: http://www.adventure-works.com/product/display/1
tán p art o pe
pe n ers rten
rm engine ec
2. The MVC routing itid @ed examines ea the request and determines that it should forward the request to the
as uc Da action.
Product Controller and las the aDisplay
c n
co ionit iel M
pia .co
3. The Display action in the Product s m ach creates a new instance of the Product model class.
Controller

4. The Product model class queries the database for information about the product with ID “1”.

https://www.skillpipe.com/#/reader/book/4ed7876c-8864-4cf5-91ee-491726dfe322 21/25
1/9/2020 Module 1: Exploring ASP.NET MVC 5

5. The Display action also creates a new instance of the Product Display View and passes the Product Model to
it.

6. The Razor view engine runs the server-side code in the Product Display View to render HTML. In this case,
the server-side code inserts properties such as Title, Description, Catalog Number, and Price into the HTML.

7. The completed HTML page is returned to the browser for display.

Es
te
do
cu
Question:No If you wanted me to write some code that renders data from your products catalog into an HTML table,
es nto
would you place pa code
tán that pine a model, a view, a controller, or a JavaScript function?
rtn rt
pe e
rm rs@ enec
itid ed ea
as uc Da
Demonstration: How las to acExplore
co ionit iel M
n an MVC Application
pia .co a ch
ss m
In this demonstration, you will see how in to use a asample do photo sharing application to explore the structure of an
au .
MVC website. t ori
za
ció
n.
Demonstration Steps

• You will find the steps in the “Lesson 3: Introduction to ASP.NET MVC 5” section on the following page:
https://github.com/MicrosoftLearning/20486-
Es
te
DevelopingASPNETMVCWebApplications/blob/master/Instructions/20486C/20486C_MOD01_DEMO.md.
do
cu
No me
es nt
tán part o pe
pe n e rt
rm rs@ enec
Lab: ExploringitidASP.NET as
ed
u
e a MVC 5
las caci Dani
co on e
pia it.co l Mac
ss m ha
Scenario in do
au .
tor
iza
You are working as a junior developer at Adventure ció
n. Works. You have been asked by a senior developer to
investigate the possibility of creating a web-based photo sharing application for your organization’s customers,
similar to one that the senior developer has seen on the Internet. Such an application will promote a community of
cyclists who use Adventure Works equipment, and the community members will be able to share their experiences.
This initiative is intended to increase the popularity of Adventure Works Cycles, and thereby to increase sales. You
have been askedEs to begin the planning of the application by examining an existing photo sharing application and
te
do
evaluating its functionality. You have also been asked to examine programming models available to ASP.NET
cu
No To do this,
developers. meyou need to create basic web applications written with three different models: Web Pages,
es nto
pa
tán MVC. pe
Web Forms, and rtn Your
pe ers rmanager
ten has asked you to report on the following specific questions for each
programming model: itid r m @ ec
ed e a
as u
las caci Dani
on
co it.c el M
• How does the developer set paiaconnection s s om astring ch and data provider?
in ad
au o.
tor
• How does the developer impose a consistent i za layout, with Adventure Works branding and menus, on all pages in
ció
the web application? n.

• How does the developer set a cascading style sheet with a consistent set of color, fonts, borders, and other
styles?

• How doesEthe developer add a new page to the application and apply the layout and styles to it?
ste
do
cu
No me
es nt
tán p art o pe
Objectives per ers rten n
mi @ e
tid ed ce a
as uc Da to:
After completing this lab, you las willacbe ablen
co ionit iel M
pia .co
s m ach
• Describe and compare the three programming models available in ASP.NET.

https://www.skillpipe.com/#/reader/book/4ed7876c-8864-4cf5-91ee-491726dfe322 22/25
1/9/2020 Module 1: Exploring ASP.NET MVC 5

• Describe the structure of each web application developed in the three programming models—Web Pages, Web
Forms, and MVC.

• Select an appropriate programming model for a given set of web application requirements.

Lab Setup

Estimated Time:Es 80 minutes


te
do
cu
N me
o ethe high-level
You will find nto steps on the following page: https://github.com/MicrosoftLearning/20486-
stá pa pe
n r t n
DevelopingASPNETMVCWebApplications/blob/master/Instructions/20486C/20486C_MOD01_LAB_MANUAL.
rt
pe e
rm rs@ enec
md. itid ed ea
as u
las caci Dani
co on e
pia it.co l Mac
You will find the detailed steps on sthe
sin following
m hpage:
ad https://github.com/MicrosoftLearning/20486-
a o.
DevelopingASPNETMVCWebApplications/blob/master/Instructions/20486C/20486C_MOD01_LAK.md.
uto
riz
ac
ión
.
Exercise 1: Exploring a Photo Sharing Application

Scenario
Es
In this exercise, te you will begin by examining the photo sharing application.
do
cu
No me
es nto
Exercise 2: pa
táExploring
n p rtne pa er Web Pages Application
erm rs@ tene
itid ed ce a
as u
las caci Dani
c on el
op i
Scenario ias t.com Mach
sin ad
au Web Pages o.
In this exercise, you will create a simple tor application and explore its structure.
iza
ció
n.
Exercise 3: Exploring a Web Forms Application

Scenario
Es
te you will create a simple Web Forms application and explore its structure.
In this exercise, do
cu
No me
es nto
Exercise 4:táExploringp
n p artne pan er MVC Application
erm rs@ tene
itid ed ce a
as u
las caci Dani
co on e
Scenario pia it.co l Mac
ss m ha
in do
In this exercise, you will create a simple tMVCa u .
ori application and explore its structure.
za
ció
n.
Review Question(s)

Check Your Knowledge


Es
te
do
Discovery cu
N me
oe nt
s p art o pe models has the simplest method of applying a single layout across multiple pages?
tán programming
Which of the three
pe n e rt
rm rs@ enec
Show solution i tReset
ida ed ea
sl uc Da
as a c n
co ionit iel M
pia .co
s m ach

Check Your Knowledge


https://www.skillpipe.com/#/reader/book/4ed7876c-8864-4cf5-91ee-491726dfe322 23/25
1/9/2020 Module 1: Exploring ASP.NET MVC 5

Discovery
Which of the three programming models has the simplest method of building a user interface?

Show solution Reset

Check Your Knowledge


Es
te
do
cu
Discovery
No me
es nt
tán part o pe
pe n rt
eprogramming
rm rs@ enec
Which of the application models will you recommend for the photo sharing application: Web Pages, Web
Forms, or MVC? itid ed ea
as u
las caci Dani
Show solution Reset op onit.
c el
ias co Mac
sin m ha
do
au .
tor
iza
Module Review and Takeaways ció
n.

In this module, you have seen the tools, technologies, and web servers that are available in the Microsoft web
stack, which you can use to build and host web applications for intranets and on the Internet. You should also be
able to distinguish applications written in the three ASP.NET programming models: Web Pages, Web Forms, and
Es
MVC. You should te be able to use MVC applications to render webpages by using models, views, and controllers.
do
cu
No me
es nt
tán part o pe
pe
Best Practice: n rt
eUse Web Pages when you have simple requirements or have developers with little
rm rs@ enec
experience ofitASP.NET.
ida ed
u
ea
sl D
as cacio anie
co nit
pia .c l M
s s om acha
in do
a .
Best Practice: Use Web Formsutwhen ori you want to create a user interface by dragging controls from a
za
toolbox onto each webpage or when your ció developers have experience of Web Forms or Windows Forms.
n.

Best Practice: Use MVC when you want the most precise control over HTML and URLs, when you want
to cleanly separate business logic, user interface code, and input logic, or when you want to perform Test
DrivenEs Development.
te
do
cu
No me
es nto
tán andp art Troubleshooting
pe
Common Issues pe n e rt Tips
rm rs@ enec
itid ed e a
as u
las caci Dani
co on e
Common Issue pia it.co l Mac Troubleshooting Tip
ss m ha
in do
You add a new view to an MVC application, but awhen .
uto you try Please see Student Companion Content for this course.
to access the page, you receive an HTTP 404 error. riza
ció
n.

Additional Reading: For more information about ASP.NET, including forums, blogs, and third-party tools,
visit the official ASP.NET site: http://go.microsoft.com/fwlink/?LinkID=293681&clcid=0x409

ste E
Review Question(s)
d oc
No um
en
es t
tán p art o pe
Check Your Knowledge
pe
rm
ne
r s
rte
ne
itid @ed ce a
as uc
las ac Dan
co ionit iel M
Discovery pia .co
s m ach
Which of the shared features of ASP.NET can you use in Web Pages, Web Forms, and MVC applications to increase the
speed with which frequently-requested pages are returned to the browser?

https://www.skillpipe.com/#/reader/book/4ed7876c-8864-4cf5-91ee-491726dfe322 24/25
1/9/2020 Module 1: Exploring ASP.NET MVC 5

Show solution Reset

Real-world Issues and Scenarios


You have written a web application for a client that sells hats. Visitors to the site will be able to register, redeem
offer vouchers, and purchase hats. You expect site traffic to be steady through most of the year, but to peak just
before Christmas. Should you recommend IIS or Microsoft Azure for hosting the site?
Es
te
do
cu
No me
es nt
tán part o pe
pe n e rt
rm rs@ enec
itid ed ea
as u
las caci Dani
co on e
pia it.co l Mac
ss m ha
in do
au .
tor
iza
ció
n.

Es
te
do
cu
No me
es nt
tán part o pe
pe n e rt
rm rs@ enec
itid ed ea
as u
las caci Dani
co on e
pia it.co l Mac
ss m ha
in do
au .
tor
iza
ció
n.

Es
te
do
cu
No me
es nt
tán p art o pe
pe n e rt
rm rs@ enec
itid ed ea
as u
las caci Dani
co on e
pia it.co l Mac
ss m ha
in do
au .
tor
iza
ció
n.

Es
te
do
cu
No me
es nt
tán p art o pe
pe n e rt
rm rs@ enec
itid ed ea
as u
las caci Dani
co on e
pia it.co l Mac
s m h

https://www.skillpipe.com/#/reader/book/4ed7876c-8864-4cf5-91ee-491726dfe322 25/25

You might also like