100% found this document useful (3 votes)
1K views

Full Download Creating ASP NET Core Web Applications Proven Approaches to Application Design and Development 1st Edition Dirk Strauss PDF DOCX

Application

Uploaded by

aidoudfukuyo
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
1K views

Full Download Creating ASP NET Core Web Applications Proven Approaches to Application Design and Development 1st Edition Dirk Strauss PDF DOCX

Application

Uploaded by

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

Download the Full Version of textbook for Fast Typing at textbookfull.

com

Creating ASP NET Core Web Applications Proven


Approaches to Application Design and Development
1st Edition Dirk Strauss

https://textbookfull.com/product/creating-asp-net-core-web-
applications-proven-approaches-to-application-design-and-
development-1st-edition-dirk-strauss/

OR CLICK BUTTON

DOWNLOAD NOW

Download More textbook Instantly Today - Get Yours Now at textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Creating ASP.NET Core Web Applications: Proven Approaches


to Application Design and Development 1st Edition Dirk
Strauss
https://textbookfull.com/product/creating-asp-net-core-web-
applications-proven-approaches-to-application-design-and-
development-1st-edition-dirk-strauss-2/
textboxfull.com

Pro ASP NET Core MVC Develop cloud ready web applications
using Microsoft s latest framework ASP NET Core MVC Sixth
Edition Adam Freeman
https://textbookfull.com/product/pro-asp-net-core-mvc-develop-cloud-
ready-web-applications-using-microsoft-s-latest-framework-asp-net-
core-mvc-sixth-edition-adam-freeman/
textboxfull.com

Ultimate ASP NET Core Web API 2nd Edition Marinko


Spasojevic

https://textbookfull.com/product/ultimate-asp-net-core-web-api-2nd-
edition-marinko-spasojevic/

textboxfull.com

Pro ASP NET Core Identity Under the Hood with


Authentication and Authorization in ASP NET Core 5 and 6
Applications 1st Edition Adam Freeman
https://textbookfull.com/product/pro-asp-net-core-identity-under-the-
hood-with-authentication-and-authorization-in-asp-net-
core-5-and-6-applications-1st-edition-adam-freeman/
textboxfull.com
C 8 0 and NET Core 3 0 Modern Cross Platform Development
Build applications with C NET Core Entity Framework Core
ASP NET Core and ML NET using Visual Studio Code 4th
Edition Mark J. Price
https://textbookfull.com/product/c-8-0-and-net-core-3-0-modern-cross-
platform-development-build-applications-with-c-net-core-entity-
framework-core-asp-net-core-and-ml-net-using-visual-studio-code-4th-
edition-mark-j-price/
textboxfull.com

Mobile Development with NET Build cross platform mobile


applications with Xamarin Forms 5 and ASP NET Core 5 2nd
Edition Can Bilgin
https://textbookfull.com/product/mobile-development-with-net-build-
cross-platform-mobile-applications-with-xamarin-forms-5-and-asp-net-
core-5-2nd-edition-can-bilgin/
textboxfull.com

Modern Web Development with ASP NET Core 3 An end to end


guide covering the latest features of Visual Studio 2019
Blazor and Entity Framework 2nd Edition Ricardo Peres
https://textbookfull.com/product/modern-web-development-with-asp-net-
core-3-an-end-to-end-guide-covering-the-latest-features-of-visual-
studio-2019-blazor-and-entity-framework-2nd-edition-ricardo-peres/
textboxfull.com

Beginning Database Programming Using ASP NET Core 3 With


MVC Razor Pages Web API jQuery Angular SQL Server and
NoSQL 1st Edition Bipin Joshi
https://textbookfull.com/product/beginning-database-programming-using-
asp-net-core-3-with-mvc-razor-pages-web-api-jquery-angular-sql-server-
and-nosql-1st-edition-bipin-joshi/
textboxfull.com

Design Patterns in .NET Core 3: Reusable Approaches in C#


and F# for Object-Oriented Software Design 2nd Edition
Dmitri Nesteruk
https://textbookfull.com/product/design-patterns-in-net-
core-3-reusable-approaches-in-c-and-f-for-object-oriented-software-
design-2nd-edition-dmitri-nesteruk/
textboxfull.com
Creating
ASP.NET Core
Web Applications
Proven Approaches to Application
Design and Development

Dirk Strauss
Creating ASP.NET Core
Web Applications
Proven Approaches to Application
Design and Development

Dirk Strauss
Creating ASP.NET Core Web Applications: Proven Approaches to
Application Design and Development
Dirk Strauss
Uitenhage, South Africa

ISBN-13 (pbk): 978-1-4842-6827-8 ISBN-13 (electronic): 978-1-4842-6828-5


https://doi.org/10.1007/978-1-4842-6828-5

Copyright © 2021 by Dirk Strauss


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not
identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Smriti Srivastava
Development Editor: Laura Berendson
Coordinating Editor: Shrikant Vishwakarma
Cover designed by eStudioCalamar
Cover image designed by Pexels
Distributed to the book trade worldwide by Springer Science+Business Media LLC, 1 New York Plaza, Suite
4600, New York, NY 10004. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.
com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner)
is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware
corporation.
For information on translations, please e-mail booktranslations@springernature.com; for reprint,
paperback, or audio rights, please e-mail bookpermissions@springernature.com, or visit http://www.apress.
com/rights-permissions.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub via the book’s product page, located at www.apress.com/978-­1-­4842-­6827-­8. For more
detailed information, please visit http://www.apress.com/source-­code.
Printed on acid-free paper
For Adele, Irénéé, and Tristan. You are my everything.
Table of Contents
About the Author����������������������������������������������������������������������������������������������������� ix

About the Technical Reviewer��������������������������������������������������������������������������������� xi


Acknowledgments������������������������������������������������������������������������������������������������� xiii
Introduction�������������������������������������������������������������������������������������������������������������xv

Chapter 1: Creating and Setting Up Your Project������������������������������������������������������ 1


Creating Your Web Application Project������������������������������������������������������������������������������������������ 1
Using the .NET CLI������������������������������������������������������������������������������������������������������������������� 5
Adding and Editing Razor Pages��������������������������������������������������������������������������������������������������� 9
Looking at the Configuration������������������������������������������������������������������������������������������������������� 19
Working with Entities������������������������������������������������������������������������������������������������������������������ 23
Creating and Registering a Data Service������������������������������������������������������������������������������������ 29
Displaying Test Data on Your Web Page�������������������������������������������������������������������������������������� 34

Chapter 2: Creating Models������������������������������������������������������������������������������������ 39


Building a Search Form��������������������������������������������������������������������������������������������������������������� 39
Adding Font Awesome����������������������������������������������������������������������������������������������������������� 39
Adding the Search Form Code����������������������������������������������������������������������������������������������� 40
Implementing the Find Logic������������������������������������������������������������������������������������������������������ 43
Using Model Binding and Tag Helpers����������������������������������������������������������������������������������������� 46
Displaying Related Data�������������������������������������������������������������������������������������������������������������� 53
Passing the Video ID Through to the Detail Page������������������������������������������������������������������� 59
Working with Page Routes���������������������������������������������������������������������������������������������������������� 63
Populating Video Details�������������������������������������������������������������������������������������������������������� 68
Handling Bad Requests��������������������������������������������������������������������������������������������������������������� 71

v
Table of Contents

Chapter 3: Modifying Data�������������������������������������������������������������������������������������� 79


Editing Existing Data and Using Tag Helpers������������������������������������������������������������������������������ 79
Building the Edit Form����������������������������������������������������������������������������������������������������������� 87
Changing the Data Service���������������������������������������������������������������������������������������������������� 95
Validate Edited Data and Display Validation Errors��������������������������������������������������������������������� 97
AddSingleton vs. AddScoped vs. AddTransient�������������������������������������������������������������������� 102
Implementing IValidatableObject����������������������������������������������������������������������������������������� 103
Adding a New Video������������������������������������������������������������������������������������������������������������������ 107
Modifying the Data Access Service������������������������������������������������������������������������������������������� 109
Modifying the OnPost Method��������������������������������������������������������������������������������������������� 110
Working with TempData������������������������������������������������������������������������������������������������������������ 111
Changing the TempData Provider���������������������������������������������������������������������������������������� 115

Chapter 4: EF Core and SQL Server����������������������������������������������������������������������� 119


Entity Framework Core������������������������������������������������������������������������������������������������������������� 119
Install Entity Framework����������������������������������������������������������������������������������������������������������� 120
Implement DbContext��������������������������������������������������������������������������������������������������������������� 124
Specify Database Connection Strings��������������������������������������������������������������������������������������� 125
Working with Database Migrations������������������������������������������������������������������������������������������� 132
Implement a New Data Access Service������������������������������������������������������������������������������������ 142
Changing the Data Access Service Registration����������������������������������������������������������������������� 145

Chapter 5: Working with Razor Pages������������������������������������������������������������������ 149


Using Sections in Your Razor Pages������������������������������������������������������������������������������������������ 149
Meta Tags and CSS�������������������������������������������������������������������������������������������������������������� 151
Navigation��������������������������������������������������������������������������������������������������������������������������� 152
@RenderBody���������������������������������������������������������������������������������������������������������������������� 152
Footer���������������������������������������������������������������������������������������������������������������������������������� 152
Scripts Applied Across All Pages����������������������������������������������������������������������������������������� 152
@RenderSection������������������������������������������������������������������������������������������������������������������ 152

vi
Table of Contents

What Are _ViewImports and _ViewStart Files?������������������������������������������������������������������������� 155


Specifying a Different Layout Page������������������������������������������������������������������������������������� 157
Creating a Custom TagHelper���������������������������������������������������������������������������������������������� 161
Working with Partial Views������������������������������������������������������������������������������������������������������� 165
Adding Video Properties and Updating the Database���������������������������������������������������������� 167
Adding Markup to the Partial View�������������������������������������������������������������������������������������� 170
Working with ViewComponents������������������������������������������������������������������������������������������������ 176

Chapter 6: Adding Client-Side Logic��������������������������������������������������������������������� 183


Separate Production Scripts from Development Scripts����������������������������������������������������������� 183
Setting Up SCSS and Generating CSS��������������������������������������������������������������������������������������� 187
SCSS Partial Files���������������������������������������������������������������������������������������������������������������� 199
Using SCSS @mixin������������������������������������������������������������������������������������������������������������� 201
Using SCSS @extend����������������������������������������������������������������������������������������������������������� 204
Using SCSS Functions��������������������������������������������������������������������������������������������������������� 208
Working with Chrome Developer Tools������������������������������������������������������������������������������������� 212
Dragging Elements�������������������������������������������������������������������������������������������������������������� 213
Adding and Modifying Styles����������������������������������������������������������������������������������������������� 215
Add a New Class������������������������������������������������������������������������������������������������������������������ 218
Testing State Changes��������������������������������������������������������������������������������������������������������� 219
Throttling Network Speed���������������������������������������������������������������������������������������������������� 221
Wrapping Up����������������������������������������������������������������������������������������������������������������������������� 223

Chapter 7: Exploring Middleware������������������������������������������������������������������������� 225


What Is Middleware������������������������������������������������������������������������������������������������������������������ 225
Handling Exceptions������������������������������������������������������������������������������������������������������������ 227
UseHsts������������������������������������������������������������������������������������������������������������������������������� 228
UseHttpsRedirection������������������������������������������������������������������������������������������������������������ 230
UseStaticFiles���������������������������������������������������������������������������������������������������������������������� 230
UseRouting�������������������������������������������������������������������������������������������������������������������������� 232
UseSession�������������������������������������������������������������������������������������������������������������������������� 232
UseEndpoints with MapRazorPages������������������������������������������������������������������������������������ 233

vii
Table of Contents

Creating Custom Middleware���������������������������������������������������������������������������������������������������� 233


Logging Information������������������������������������������������������������������������������������������������������������������ 238
Only Logging What Is Necessary����������������������������������������������������������������������������������������������� 244
Applying a Specific LogLevel to Production������������������������������������������������������������������������������ 247
A Quick Look at the Log Category��������������������������������������������������������������������������������������������� 254
Wrapping Up����������������������������������������������������������������������������������������������������������������������������� 255

Chapter 8: Web Application Deployment�������������������������������������������������������������� 257


Getting Your Site Ready for Deployment����������������������������������������������������������������������������������� 257
Deploying Your Web Application to IIS��������������������������������������������������������������������������������������� 265
Configuring the SQL Server Database��������������������������������������������������������������������������������� 271
A Note About Connection Strings and Secrets�������������������������������������������������������������������� 283

Index��������������������������������������������������������������������������������������������������������������������� 285

viii
About the Author
Dirk Strauss is a software developer from South Africa
who has been writing code since 2003. He has extensive
experience in SYSPRO, with C# and web development being
his main focus. He studied at the Nelson Mandela University,
where he wrote software on a part-time basis to gain a better
understanding of the technology. He remains passionate
about writing code and imparting what he learns to others.

ix
About the Technical Reviewer
Carsten Thomsen is a back-end developer primarily but
working with smaller front-end bits as well. He has authored
and reviewed a number of books and created numerous
Microsoft Learning courses, all to do with software
development. He works as a freelancer/contractor in various
countries in Europe; Azure, Visual Studio, Azure DevOps,
and GitHub are some of the tools he works with. Being an
exceptional troubleshooter, asking the right questions,
including the less logical ones, in a most logical to least
logical fashion, he also enjoys working with architecture,
research, analysis, development, testing, and bug fixing.
Carsten is a very good communicator with great mentoring and team-lead skills, and
great skills in researching and presenting new material.

xi
Acknowledgments
I would like to thank my wife and kids for their support during the writing of this book.
I love you always!

xiii
Introduction
.NET Core has given .NET developers a lot to think about. Some developers have
embraced the technology, while others have taken a wait-and-see approach. Whatever
approach you are taking, .NET Core is without a doubt here to stay.
Developing web applications is also not one of the easiest things to do. I’ve always
wanted to write a book on developing web applications, but to do it in a way that is very
structured and takes the reader on a journey of discovery.
Creating ASP.NET Core Web Applications is my attempt at that book. I always try to
take the point of view that the book I’m writing is a reference book for my bookshelf.
With this in mind, I, therefore, tried to cover a wide set of topics.
As with all projects, Chapter 1 starts with creating your project and using the .NET
CLI. We have a look at adding Razor pages and also how to configure the application
using the appsettings.json file. I then create a dummy data service, which is used to get
the application up and running with test data. This test data is designed in such a way
that it can easily be swapped out at a later stage (and I show you how to do this).
Chapter 2 takes a look at the process of creating models, model binding, tag helpers,
working with a query string, and page routes. To illustrate these concepts, Chapter 2
shows you how to implement a search form. This allows us to search for data, view the
details, and add in logic to handle bad requests.
Chapter 3 illustrates the concepts of editing the data, displaying validation errors,
and modifying the data access service to suit our needs. I also discuss the differences
between singleton, scoped, and transient lifetime registration for services.
EF Core and SQL Server become the focus in the next chapter. Chapter 4 shows
you how to install Entity Framework Core, define your connection strings, what
database migrations are, and how to use them. We will also be implementing a new
data access service and changing the data access service registration from the test
data to the SQL data.

xv
Introduction

Moving to the front end next, we have a look at working with Razor pages in Chapter 5.
Here, we will look at what sections are and how they benefit you as a developer. We take a
closer look at _ViewImports and _ViewStart files. I also show you how to create your own tag
helper, how to work with partial views, and, finally, how to work with ViewComponents.
Staying front end, we have a look at adding client-side logic in Chapter 6. I show
you how to separate production scripts from development scripts, use SCSS to generate
CSS, how SCSS works, and the different features you can use to create CSS with SCSS, as
well as work with Chrome Developer Tools. This is, in my opinion, crucial for any web
developer to know.
With Chapter 7, we will take a look at what middleware is. This is a very important
chapter and one that will require some explaining. We have a look at some of the built-­
in middleware components, but also how to create a custom middleware component
if the built-in middleware components don’t suit your needs. After creating a custom
middleware component, we will have a look at logging in ASP.NET Core. Logging is a big
subject, but this book tries to cover the basics.
Finally, Chapter 8 will take you through getting your web application ready for
deployment and finally publishing your web application and hooking it up to a SQL
Server database. I hope that you will enjoy this book as much as I enjoyed writing it.

xvi
CHAPTER 1

Creating and Setting


Up Your Project
Welcome to Creating ASP.NET Core Web Applications! This book will guide you through
creating a typical ASP.NET Core Web Application, from start to finish. All the code
illustrated in this book is available on GitHub and will be an invaluable resource to you
as you navigate the code samples in the book.
This chapter will take you through the steps required to start your web application
development. We will also have a look at adding and editing Razor pages, working with
Entities, creating and registering a data service, and using that data service to display test
data on the web page.

Creating Your Web Application Project


In this book, I will be using Visual Studio 2019 to illustrate the concepts surrounding
ASP.NET Core Web Applications. For those folks that do not use Visual Studio, the same
result as detailed in the following can be achieved for creating an application by using
the .NET CLI.

I will assume that you have already installed .NET Core onto your machine. The
web application we will be creating will use .NET Core 3.1. If you have not installed
.NET Core, you can do so by visiting this link: https://dotnet.microsoft.
com/download.

Because we are working with .NET Core which is cross-platform, I will also show you
how to create an application using the Command Prompt later in this section.

1
© Dirk Strauss 2021
D. Strauss, Creating ASP.NET Core Web Applications, https://doi.org/10.1007/978-1-4842-6828-5_1
Chapter 1 Creating and Setting Up Your Project

For now, let us start by creating a new project in Visual Studio. From the file menu,
click New Project. This will display the Create a new project screen as seen in Figure 1-1.

Figure 1-1. The Create New Project Screen

The Create a new project screen that allows you to select the correct project template
lists all the available templates included in Visual Studio. In our case, we will be using
the ASP.NET Core Web Application template.
If you are used to working in previous versions of Visual Studio, you will notice that
this screen has been vastly improved. You can search for templates by typing a template
name into the search text box or by holding down Alt+S.
You can also filter project templates from the drop-downs on the form. You will
notice that you can filter by language, platform, and project type.
Clicking the Next button will take you to the Configure your new project screen as
seen in Figure 1-2.

2
Chapter 1 Creating and Setting Up Your Project

Figure 1-2. Configure Your New Project

Give the project a suitable name. For this book, we will simply call the project
VideoStore and specify a location to create the project in. When you have done this, click
the Create button.
You will now be taken to a second screen as seen in Figure 1-3 where you can select
the specific type of template that you want to use.

3
Chapter 1 Creating and Setting Up Your Project

Figure 1-3. Selecting a Specific Template Type

It is here that we can specify the version of .NET Core that we want to use. In this
example, we are selecting .NET Core 3.1. We can then tell Visual Studio that we want to
create a basic web application. Just leave the rest of the settings at their default values
and click the Create button.

4
Chapter 1 Creating and Setting Up Your Project

Figure 1-4. Running the Web Application

After the project has been created in Visual Studio, you can hit Ctrl+F5 to run the
web application. This will run your project without the debugger attached and display
the web application in your browser as seen in Figure 1-4.
You will notice that the web application is running on port 44398 in this example,
but your port will most likely be different. By default, this web application includes some
basic features such as a Home page as well as a Privacy page.
It is from here that we will start to flesh out our web application and add more
features and functionality to it.

Using the .NET CLI


Earlier in this chapter, I mentioned that we can also create the project from the
Command Prompt. Therefore, for those of you that do not use Visual Studio, the .NET
CLI offers a cross-platform way for creating .NET Core projects.

5
Chapter 1 Creating and Setting Up Your Project

Once you have installed .NET Core on your Mac, Linux, or Windows machine, you
should be able to simply open your Terminal, Shell, or Command Prompt and type the
dotnet command as seen in Figure 1-5.

Figure 1-5. Running the dotnet Command

To see more of the commands available with dotnet, you can type dotnet -h in the
Command Prompt. If you typed in dotnet new, you would see all the available project
templates listed in your Command Prompt window.
These templates, along with the short name associated with that specific template,
are listed in the following table.

Templates Short Name Language Tags

Console Application Console C#, F#, VB Common/


Console
Class library classlib C#, F#, VB Common/
Library
WPF Application wpf C# Common/WPF
WPF Class library wpflib C# Common/WPF
(continued)

6
Chapter 1 Creating and Setting Up Your Project

Templates Short Name Language Tags

WPF Custom Control Library wpfcustomcontrollib C# Common/WPF


WPF User Control Library wpfusercontrollib C# Common/WPF
Windows Forms (WinForms) Application winforms C# Common/
WinForms
Windows Forms (WinForms) Class library winformslib C# Common/
WinForms
Worker Service worker C# Common/
Worker/Web
Unit Test Project mstest C#, F#, VB Test/MSTest
NUnit 3 Test Project nunit C#, F#, VB Test/NUnit
NUnit 3 Test Item nunit-test C#, F#, VB Test/NUnit
xUnit Test Project xunit C#, F#, VB Test/xUnit
Razor Component razorcomponent C# Web/ASP.NET
Razor Page page C# Web/ASP.NET
MVC ViewImports viewimports C# Web/ASP.NET
MVC ViewStart viewstart C# Web/ASP.NET
Blazor Server App blazorserver C# Web/Blazor
Blazor WebAssembly App blazorwasm C# Web/Blazor/
WebAssembly
ASP.NET Core Empty web C#, F# Web/Empty
ASP.NET Core Web App (Model-View-­ mvc C#, F# Web/MVC
Controller)
ASP.NET Core Web App webapp C# Web/MVC/
Razor Pages
ASP.NET Core with Angular angular C# Web/MVC/SPA
ASP.NET Core with React.js React C# Web/MVC/SPA
ASP.NET Core with React.js and Redux Reactredux C# Web/MVC/SPA
(continued)

7
Chapter 1 Creating and Setting Up Your Project

Templates Short Name Language Tags

Razor Class Library Razorclasslib C# Web/Razor/


Library/
Razor Class Library
ASP.NET Core Web API Webapi C#, F# Web/WebAPI
ASP.NET Core gRPC Service Grpc C# Web/gRPC
dotnet gitignore file gitignore Config
global.json file globaljson Config
NuGet Config nugetconfig Config
Dotnet local tool manifest file tool-manifest Config
Web Config webconfig Config
Solution File sln Solution

You will notice that to create an ASP.NET Web Application, we need to specify the
short name webapp with the new command.
As seen in Figure 1-6, typing in the command dotnet new webapp will create the
ASP.NET Web Application inside the current directory.

Figure 1-6. Creating the Web App via the .NET CLI
8
Chapter 1 Creating and Setting Up Your Project

If you had to compare the project created via the .NET CLI with the one created in
Visual Studio, you will see that these are identical.
The .NET CLI offers a fantastic, quick, and cross-platform way of creating
applications.

Adding and Editing Razor Pages


With your web application running, you will notice that if you click the Privacy link in the
navigation menu, it will go to the following URL: https://localhost:44398/Privacy.
The web application is mapping the request created by clicking the Privacy link with
the Razor pages in your VideoStore project. Looking at Figure 1-7, you will see the Razor
pages in a folder called… you guessed it, Pages.

Figure 1-7. The Razor Pages in the Solution Explorer

This means that when I view the Privacy page in the web application, ASP.NET Core
is busy rendering the Privacy.cshtml page. You will also notice that the cshtml extension
is not required in the URL as seen in Figure 1-8.
9
Chapter 1 Creating and Setting Up Your Project

Figure 1-8. The Privacy Policy Page

You will also notice that when you make your browser window smaller, the menu
collapses into the hamburger icon. This is made possible by Bootstrap, which is included
in the project by default.
If you now click your Privacy.cshtml page in the Solution Explorer, you will see the
code as listed in Code Listing 1-1.

Listing 1-1. The Privacy Razor Page


@page
@model PrivacyModel
@{
    ViewData["Title"] = "Privacy Policy";
}
<h1>@ViewData["Title"]</h1>

<p>Use this page to detail your site's privacy policy.</p>

With your web application running without the debugger attached, if you click the
hamburger menu icon, you will see that we have just two pages listed which are Home
and Privacy.

10
Chapter 1 Creating and Setting Up Your Project

Looking at Figure 1-9 and comparing that to the code in Code Listing 1-1, you might
be wondering where the code is for the navigation.

Figure 1-9. The Navigation Menu

The answer lies in a special Razor page called a Layout page. Swing back to your
Solution Explorer, and expand the Shared folder under the Pages folder. There you will
see a page called _Layout.cshtml as seen in Figure 1-10.

11
Chapter 1 Creating and Setting Up Your Project

Figure 1-10. The Shared Layout Page

It is this Layout page that renders everything within the web application's <head>
tags, things such as links to all the required stylesheets, as well as <body> tags that
include a <header> section containing the navigation menu. The code for the navigation
menu is listed in Code Listing 1-2.

Listing 1-2. The Navigation Menu Code


<div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
  <ul class="navbar-nav flex-grow-1">
    <li class="nav-item"><a class="nav-link text-dark" asp-area="" asp-­
page="/Index">Home</a></li>
    <li class="nav-item"><a class="nav-link text-dark" asp-area="" asp-­
page="/Privacy">Privacy</a></li>
  </ul>
</div>

12
Chapter 1 Creating and Setting Up Your Project

Go ahead and add another menu item called Videos, by adding a new list item to the
unordered list as seen in Code Listing 1-3.

Listing 1-3. Modified Navigation Menu Code

<div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">


  <ul class="navbar-nav flex-grow-1">
    <li class="nav-item"><a class="nav-link text-dark" asp-area="" asp-­
page="/Index">Home</a></li>
    <li class="nav-item"><a class="nav-link text-dark" asp-area="" asp-­
page="/ Videos/List">Videos</a></li>
    <li class="nav-item"><a class="nav-link text-dark" asp-area="" asp-­
page="/Privacy">Privacy</a></li>
  </ul>
</div>

You will notice that the asp-page tag helper specifies Videos/List which tells my
web application that inside a folder called Videos is a page that will display a list of
videos. Running your web application again, you will see that the Videos menu item has
been added to the navigation menu (Figure 1-11).

13
Chapter 1 Creating and Setting Up Your Project

Figure 1-11. Navigation Menu Modified

If you click the Videos menu item, the link will not navigate anywhere. This is
because we have not yet added the required Razor page. As shown in Figure 1-12, add a
new folder under the Pages folder in your Solution Explorer.

14
Chapter 1 Creating and Setting Up Your Project

Figure 1-12. Adding the Videos Folder

Next, right-click the Videos folder, and add a new Razor page called List to the
folder. This can be done from the context menu or from the Add New Item screen as
shown in Figure 1-13.

15
Chapter 1 Creating and Setting Up Your Project

Figure 1-13. Adding a New Razor Page

Once the List.cshtml page has been added, you will notice that Visual Studio has
added a second page (Figure 1-14) called List.cshtml.cs. The List.cshtml file is
essentially my Razor page containing the @page directive (Code Listing 1-4).

Listing 1-4. Razor Page Code

@page
@model VideoStore.Pages.Videos.ListModel
@{
}

Furthermore, the Razor page also specifies a model with the @model directive. It
is telling .NET Core that the model that contains video information is contained in an
object of type ListModel.

16
Random documents with unrelated
content Scribd suggests to you:
such as appear are usually goddesses or accessory persons in
mythical scenes; but with the gradual change to subjects taken from
every-day life in the later sixth and the early fifth century, we begin to
see women about their usual occupations, or in groups talking with
each other or with men. Much of the later Athenian pottery is
decorated with charming scenes from the life of women, showing
them with their children, at their toilet, busy with embroidery, or
playing with pets. The younger ones seem to have enjoyed some
games which we have relegated to childhood, such as spinning tops
(see fig. 53). On the marriage-vases we see the bride being dressed
by her friends and servants, or receiving presents on the day after
the wedding, the traditional occasion for the presentation of gifts.
Two of these vases are in Case B in the Fifth Room (fig. 45), and a
perfume vase in Case Q is decorated with a similar scene. The usual
presents seem to have been bands and ribbons for the hair,
perfumes, jewelry, and pets, especially birds.
V
CHILDREN AND EDUCATION
CASES 2 AND 3

Little babies were tightly bound in swaddling clothes soon after


birth, and the mother, in anxiety for her child’s safety, usually
fastened an amulet or charm of some kind around its neck to keep
away unfriendly spirits. The grotesque faces of colored glass
previously mentioned (p. 8) may have served this purpose. Roman
children wore the bulla, a case of leather or gold, according to the
means of the parents, containing a charm. A large gold bulla of
Etruscan workmanship is in a case at the left side of the Gold Room
(fig. 46). The baby became the charge of an old and trusted slave-
woman such as the kind old nurse represented in a terracotta
statuette on the middle shelf of Case 3. Another of the same type is
in Case K in the Sixth Room (fig. 47). The prettily decorated jug with
a spout is a feeding-bottle (fig. 48).
FIG. 46. GOLD BULLA

FIG. 48. TERRACOTTA


FIG. 47. OLD NURSE HOLDING FEEDING-BOTTLE
A BABY

Greek and Roman children played with toys much like those of the
present day, but they were simple and inexpensive. Rattles for
babies were made of terracotta with a few pebbles enclosed (Case
3, middle shelf). An interesting toy for a small child is the terracotta
horse from Cyprus with large jars in its panniers such as those
carried by real horses for taking provisions to and from market (Case
2, top shelf, fig. 49). Carts were favorite playthings; a small oinochoë
in Case 3 shows a boy driving two goats harnessed to a chariot, and
on a white lekythos painted for a child’s grave (Case F in the Fifth
Room), a little boy is going to Charon’s boat for his journey over the
Styx, drawing his toy cart (fig. 50). Of course, Greek and Roman
children kept house with their dolls, and charming miniature vases
were made for them, some for the doll’s table and others for her
toilet and wedding. These vases, which are decorated with scenes of
children at play, were given, it is thought, as presents on a festival
day called Choes, “Jugs.” A number of different types are in Case G
in the Fifth Room.

FIG. 49. TOY HORSE ON WHEELS

Dolls were made of wax and clay. The two seated terracotta dolls
without joints in Case L in the Seventh Room were found in graves
at Tarentum in Southern Italy. Another made of bone has jointed
arms and could easily be dressed (Case 3, tail-piece, p. 46). These
dolls were originally painted in bright colors, which have been
destroyed by time.
FIG. 50. TOMB LEKYTHOS.
CHILD DRAWING A CART

Rolling hoops, contrary to modern ideas, seems to have been a


boys’ sport. A boy with a hoop may be seen on a vase in Case J in
the Fifth Room (fig. 52). Mothers and nurses swung small children in
swings, as in the scene on a vase from Southern Italy (Case P, Sixth
Room), and older girls also enjoyed this pastime. As part of a game
or perhaps as forfeit, girls sometimes carried one another on their
backs. A terracotta statuette represents two girls playing
ephedrismos, as this game was called (Case 3, fig. 55). Young
women and girls, as well as boys, played with whipping-tops, as is
shown on a lekythos on the same shelf (fig. 53), and on one side of a
toilet-box two girls are playing a game of ball with a wicket (fig. 51).
Children also played hide-and-seek, tug-of-war, and many games
with beans, nuts, pebbles, small coins, and the astragals described
in the section on Amusements (pp. 68-69).

FIG. 51. GIRLS PLAYING BALL

At about six years of age Greek boys were sent to school, while
the girls remained at home to learn from their mothers how to spin
and weave, and to read a little and keep accounts. Their education
was of the simplest kind and ceased very early.

FIG. 52. BOY ROLLING A HOOP


FIG. 53. WOMEN WHIPPING TOPS

FIG. 54. STYLUS

The first school to which a boy went was that of the letter-teacher,
who taught reading, writing, and simple arithmetic. A kylix in Case 3
(see head-band, p. 40) is decorated with figures of schoolboys, one
of whom holds a roll of manuscript, and another a writing tablet.
These tablets were thin pieces of wood covered with wax and
fastened together with cords (fig. 56). A pointed stylus (fig. 54) was
used for writing, the blunt end being turned around when it was
necessary to erase by smoothing the wax[1]. After three or four years
in the letter-school the boys went to the music teacher, who taught
them to sing and to play the lyre, and in connection with the music
they learned many selections from the great poets. Training in the
palaistra or wrestling-school was begun very early, and was usually
continued until the boy was old enough to be called into the military
service of the state. These lessons will be described in the section
on athletics, as the sports of the palaistra were in general the same
as those of the men’s gymnasium. In addition to the subjects already
mentioned, many boys, during the fifth century and later, studied
geometry, rhetoric, and philosophy.

[1] Several very interesting objects illustrating Greek writing and


writing-materials are exhibited in the case devoted to learning in
the Seventh Egyptian Room. They include a wooden tablet
covered with wax, several short letters on potsherds—a cheap
and common writing-material—and fragments of the Iliad and the
Odyssey on papyrus, the usual substance on which books were
written, dating from the third century B.C. The reed pens in this
case are of the kind employed for writing on papyrus.
FIG. 56. BOY WITH A WRITING TABLET

FIG. 55. EPHEDRISMOS GAME

FIG. 57. INK-POT

In Italy, Greek ideas of education were generally adopted; boys


learned the Greek language and studied the Greek and Roman
poets. A little geography and history were taught, and arithmetic
occupied much time, for the Roman system of weights, measures,
and coins was difficult and inconvenient. Besides the schools for
elementary subjects there were special classes for the study of
rhetoric and philosophy. The children of rich or noble families were
often educated at home by Greek tutors, the girls and boys together,
and among the humbler people they went to the same school for a
time. In general the education of girls was similar to that of boys, so
far as it went, and sometimes in wealthy families was continued after
marriage. Many ladies knew the Greek poets well and wrote verses
themselves. Music occupied much of their time and they learned to
dance for recreation and as a means of giving pleasure to their
families and friends.
VI
DRESS AND TOILET
CASES 2, 3, AND 5

FIG. 58. DIAGRAM OF DORIC CHITON


Greek dress, both for men and women, consisted of two portions,
a garment for the house and a wrap to be worn over it. Men, from the
time of the Homeric poems downwards, wore a “chiton,” rectangular
in shape and somewhat wider than the body, closed on the sides
and across the top except for openings left for the head and arms. A
short woolen chiton was the usual dress for soldiers, workmen, and
poor persons, while the nobles of the Homeric poems seem to have
worn linen chitons reaching to the feet. Over this a wrap, either
rectangular or curved on one side, was arranged in various ways.
The earliest representations show men wearing a wrap with one
curved edge, and apparently doubled like a shawl. This type of dress
may be seen in vase paintings in the Third Room; for example, the
figure of Dionysos on a stamnos (No. GR 564 in Case R), and the
same god on a large amphora (No. 12.198.4) in that case.

FIG. 59. AMAZONS IN MEN’S IONIC CHITONS

The earliest garment for women which we know of was a chiton of


wool without sewing. This was a large rectangular piece of cloth
considerably wider and longer than the body. It was folded through
the middle lengthwise, so that one side was closed and the other
open. The top, again, was generally folded over, this hanging portion
being called “apoptygma.” Long pins inserted with the points
upwards, or fibulae (see head-band, p. 47), were used to fasten the
double edge on the shoulders, and a girdle was usually worn to hold
the edges of the open side in place (fig. 58). If the chiton were still
too long, part of the cloth was drawn up through the girdle into a
blouse called “kolpos.” The heavy woolen chiton may be seen in the
drawing of three nymphs on an amphora (No. GR 549) in Case K in
the Third Room. From these early representations in art, it seems
that clothing for both men and women was at first rather narrow and
was often covered with woven or embroidered patterns (fig. 60).
During the seventh and sixth centuries the rich and artistic Ionian
cities had a great influence on the customs of Greece, and from
them the ladies of Athens adopted the linen chiton, which was wider
and was sewed on the sides. The additional width was sometimes
used to form sleeves by catching the two pieces together at the top
in three or four places, with sewing, buttons, or small pins. Long
sleeves sewn in were occasionally worn, but were exceptional rather
than customary, so that artists often represent barbarians with
sleeves to distinguish them from Greeks. On a kotyle in Case C in
the Fifth Room is a woman wearing a spotted chiton with long, close-
fitting sleeves. At this period men as well as women at times wore
the apoptygma and kolpos, but the man’s chiton was generally short
(fig. 59). On two kylikes on the bottom of Case L in the Fourth Room
(Nos. 12.231 and GR1120) women are represented in the linen
chiton (fig. 62). After the Persian Wars, as the result of the strong
reaction against Eastern fashions, men and women both adopted the
woolen Doric chiton again, and for men it remained the universal
dress, being now short and without apoptygma and kolpos. Still, the
adoption of the Doric chiton did not imply a violent change, for
working people had worn it continuously and it was the usual dress
for young girls. Old men, priests, charioteers, and officials on public
occasions continued to wear the long Ionic chiton, and both were in
use by ladies at the same period. It should be added that at this time
the two types were often worn together, the Ionic forming an
undergarment with short sleeves, and the Doric, a sleeveless gown.
This costume is frequently seen on grave-reliefs, but our only
example is an engraving of a Maenad on a bronze mirror in Case C
in the Sixth Room.

FIG. 60. EARLY CHITONS

FIG. 61. WOMAN’S DORIC


CHITON OF THE V CENTURY
FIG. 62. WOMAN IN IONIC CHITON

The woman’s Doric chiton of this time may be seen in the statue of
Eirene, No. 15 in the Sculpture Gallery (fig. 61), and it is worn
without a girdle by the young girl on a gravestone (No. 21, fig. 63).
Here the open side shows plainly. A drawing of Zeus on a krater on
the bottom of Case O in the Fourth Room, and a young hunter on a
krater on the left side of the first shelf show the man’s chiton (fig. 67).
The Ionic chiton is illustrated by the statue of a goddess, No. 19 in
the Sculpture Gallery. Metal buttons to represent the sleeve
fastenings were inserted in the marble.
FIG. 63. DORIC CHITON
WITHOUT GIRDLE
FIG. 64. LADY IN HIMATION
AND HAT
FIG. 65. LADY IN HIMATION
FIG. 66. MAN IN RIDING-CLOAK
AND HAT

The usual outer wrap, called himation, was a large oblong,


rectangular piece of woolen cloth, and was practically the same for
both sexes. In the seventh and sixth centuries there were various
ways of arranging it; as a shawl, or as a scarf fastened on one
shoulder. The archaic statue of a woman, No. 2 in the Sculpture
Gallery, wears it doubled and fastened on one shoulder over an Ionic
chiton of soft, crinkled linen (fig. 68). Gradually a simpler and more
beautiful arrangement was adopted; the himation was laid across the
back with one corner over the left shoulder, then folded around the
front of the body, passing either over or under the right arm
according to the wearer’s wish, and the end thrown over the left
shoulder, from which it hung down the back, kept in place by a
weight in the corner. On a krater (No. 16.72) on the bottom of Case J
in the Fourth Room, the god Dionysos is wearing the himation
arranged in this way (see tail-piece, p. 67), and the cast of the so-
called Lateran Sophokles (No. 775 in the Gallery of Casts) shows
the himation at its best. Ladies often drew it up over their heads like
a veil. The terracotta statuettes in the Sixth Room illustrate the
variety of ways in which the wrap could be draped (figs. 64, 65).
Besides the himation there were cloaks of more convenient
dimensions for riding, hunting, or traveling. These were variously
named but were all unsewn pieces of cloth, rectangular or curved on
one side, and were usually pinned on one shoulder. A terracotta (No.
06.1118) in Case G in the Sixth Room represents a traveler in chiton
and riding-cloak (fig. 66), and the same cloak is worn by a warrior on
the large amphora on a pedestal in the Fifth Room (see fig. 103).
FIG. 67. MAN’S CHITON

Head-coverings were worn only by travelers, riders, or working-


men. A hat with a wide brim, called “petasos,” was the usual
traveler’s head-gear. It was made in a variety of shapes, the brim
being sometimes broader at back and front, sometimes at the sides.
Another form had a circular brim which turned up. This may be seen
on three terracotta statuettes (Case 2, and Case G in the Sixth
Room). A cap, called “pilos,” was worn by smiths, sailors, and
working-men in general. There is a man wearing a pilos on a cup on
the top shelf of Case S in the Fourth Room, and a warrior with the
same hat will be found on a small hydria on the first shelf of Case Q
in the Fifth Room. Some head-coverings which may be either caps
or small hats with rolled brims, are represented in several terracotta
statuettes of boys in Case G in the Sixth Room. Women wore the
petasos for traveling, and they also used a kind of sun-hat, called
“tholia,” with a pointed crown and broad brim, made of straw and
fastened by a ribbon. Several examples of this stiff and ungraceful
hat may be seen on terracotta statuettes in Case 2, and in Case G in
the Sixth Room (see fig. 64).
FIG. 68. AKROPOLIS MAIDEN
IN IONIC CHITON AND
HIMATION

Shoes were of two principal types: sandals with straps, and high
shoes or boots for hunting and traveling. The Greeks valued finely
made shoes, and dandies sometimes invented new fashions which
were called by their names, as “Alkibiades shoes.” A terracotta foot
from Cyprus wearing a sandal and another painted black are on the
middle shelf of Case 2. On a krater in Case O in the Fourth Room
Hermes wears high laced boots with a tongue rising above the laces,
and a stamnos on the bottom of Case E shows the hunter Eos in
boots. The bronze statuette of the philosopher Hermarchos in the
Seventh Room wears sandals which are worked out in detail (fig.
69), and an idea of the thickness of the soles may be gained from
those worn by the woman on a stele, No. 4 in the Sculpture Gallery.
The number and arrangement of the straps which held the sandal in
place were various and they were sometimes broad enough to form
what was practically a shoe. Boots were at times made with the leg-
covering composed of leather bands resembling modern puttees.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like