100% found this document useful (2 votes)
97 views65 pages

Pro ASP NET Core MVC Develop Cloud Ready Web Applications Using Microsoft S Latest Framework ASP NET Core MVC Sixth Edition Adam Freeman Download PDF

Core

Uploaded by

jbelliarenca87
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
97 views65 pages

Pro ASP NET Core MVC Develop Cloud Ready Web Applications Using Microsoft S Latest Framework ASP NET Core MVC Sixth Edition Adam Freeman Download PDF

Core

Uploaded by

jbelliarenca87
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 65

Experience Seamless Full Ebook Downloads for Every Genre at textbookfull.

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/

OR CLICK BUTTON

DOWNLOAD NOW

Explore and download more ebook at https://textbookfull.com


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

Pro ASP.NET Core MVC 2: Develop cloud-ready web


applications using Microsoft’s latest framework, ASP.NET
Core MVC 2 — Seventh Edition Adam Freeman
https://textbookfull.com/product/pro-asp-net-core-mvc-2-develop-cloud-
ready-web-applications-using-microsofts-latest-framework-asp-net-core-
mvc-2-seventh-edition-adam-freeman/
textboxfull.com

Pro ASP.NET Core 3: Develop Cloud-Ready Web Applications


Using MVC, Blazor, and Razor Pages — Eighth Edition Adam
Freeman
https://textbookfull.com/product/pro-asp-net-core-3-develop-cloud-
ready-web-applications-using-mvc-blazor-and-razor-pages-eighth-
edition-adam-freeman/
textboxfull.com

Programming Microsoft ASP NET MVC Dino Esposito

https://textbookfull.com/product/programming-microsoft-asp-net-mvc-
dino-esposito/

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
Pro Entity Framework Core 2 for ASP.NET Core MVC Adam
Freeman

https://textbookfull.com/product/pro-entity-framework-core-2-for-asp-
net-core-mvc-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

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

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

Essential Angular for ASP.NET Core MVC 3 Adam Freeman

https://textbookfull.com/product/essential-angular-for-asp-net-core-
mvc-3-adam-freeman/

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
Pro ASP.NET Core MVC
Sixth Edition

Adam Freeman
Pro ASP.NET Core MVC: Sixth Edition

Adam Freeman
ISBN-13 (pbk): 978-1-4842-0398-9 ISBN-13 (electronic): 978-1-4842-0397-2
DOI 10.1007/978-1-4842-0397-2
Library of Congress Control Number: 2016953186
Copyright © 2016 by Adam Freeman
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: Welmoed Spahr
Lead Editor: Gwenan Spearing
Technical Reviewer: Fabio Claudio Ferracchiati
Editorial Board: Steve Anglin, Pramila Balan, Laura Berendson, Aaron Black, Louise Corrigan,
Jonathan Gennick, Robert Hutchinson, Celestin Suresh John, Nikhil Karkal, James Markham,
Susan McDermott, Matthew Moodie, Natalie Pao, Gwenan Spearing
Coordinating Editor: Mark Powers
Copy Editor: Kim Wimpsett
Compositor: SPi Global
Indexer: SPi Global
Artist: SPi Global
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street,
6th Floor, New York, NY 10013. 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 [email protected], or visit www.apress.com.
Apress and friends of ED books 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 Special
Bulk Sales–eBook Licensing web page at www.apress.com/bulk-sales.
Any source code or other supplementary materials referenced by the author in this text are available to
readers at www.apress.com/9781484203989. For detailed information about how to locate your book’s source
code, go to www.apress.com/source-code/. Readers can also access source code at SpringerLink in the
Supplementary Material section for each chapter.
Printed on acid-free paper
Dedicated to my lovely wife, Jacqui Griffyth (and also to Peanut).
Contents at a Glance

About the Author .................................................................................................xxvii


About the Technical Reviewer ..............................................................................xxix

■Part I: Introducing ASP.NET Core MVC ................................................ 1


■Chapter 1: ASP.NET Core MVC in Context ............................................................... 3
■Chapter 2: Your First MVC Application ................................................................ 11
■Chapter 3: The MVC Pattern, Projects, and Conventions ..................................... 53
■Chapter 4: Essential C# Features......................................................................... 65
■Chapter 5: Working with Razor ......................................................................... 101
■Chapter 6: Working with Visual Studio .............................................................. 123
■Chapter 7: Unit Testing MVC Applications ......................................................... 159
■Chapter 8: SportsStore: A Real Application ....................................................... 191
■Chapter 9: SportsStore: Navigation ................................................................... 235
■Chapter 10: SportsStore: Completing the Cart .................................................. 269
■Chapter 11: SportsStore: Administration .......................................................... 291
■Chapter 12: SportsStore: Security and Deployment .......................................... 319
■Chapter 13: Working with Visual Studio Code ................................................... 343
■Part II: ASP.NET Core MVC in Detail ................................................ 371
■Chapter 14: Configuring Applications................................................................ 373
■Chapter 15: URL Routing.................................................................................... 425
■Chapter 16: Advanced Routing Features ........................................................... 465

v
■ CONTENTS AT A GLANCE

■Chapter 17: Controllers and Actions.................................................................. 503


■Chapter 18: Dependency Injection ..................................................................... 547
■Chapter 19: Filters ............................................................................................. 581
■Chapter 20: API Controllers ............................................................................... 621
■Chapter 21: Views ............................................................................................. 653
■Chapter 22: View Components .......................................................................... 687
■Chapter 23: Understanding Tag Helpers ............................................................ 719
■Chapter 24: Using the Form Tag Helpers ........................................................... 753
■Chapter 25: Using the Other Built-in Tag Helpers .............................................. 779
■Chapter 26: Model Binding ................................................................................ 805
■Chapter 27: Model Validation ............................................................................ 843
■Chapter 28: Getting Started with Identity .......................................................... 877
■Chapter 29: Applying ASP.NET Core Identity ...................................................... 919
■Chapter 30: Advanced ASP.NET Core Identity .................................................... 949
■Chapter 31: Model Conventions and Action Constraints ................................... 983

Index ................................................................................................................... 1013

vi
Contents

About the Author .................................................................................................xxvii


About the Technical Reviewer ..............................................................................xxix

■Part I: Introducing ASP.NET Core MVC ................................................................... 1


■Chapter 1: ASP.NET Core MVC in Context ............................................................... 3
Understanding the History of ASP.NET Core MVC ............................................................. 3
ASP.NET Web Forms................................................................................................................................ 3
The Original MVC Framework ................................................................................................................. 5

Understanding ASP.NET Core ............................................................................................ 5


Key Benefits of ASP.NET Core MVC ......................................................................................................... 6

What Do I Need to Know? ................................................................................................. 8


What Is the Structure of This Book? ................................................................................. 8
Part 1: Introducing ASP.NET Core MVC.................................................................................................... 8
Part 2: ASP.NET Core MVC in Detail......................................................................................................... 9
What’s New in This Edition? ............................................................................................. 9
Where Can I Get the Example Code? ................................................................................ 9
Summary .......................................................................................................................... 9
■Chapter 2: Your First MVC Application ................................................................ 11
Installing Visual Studio ................................................................................................... 11
Creating a New ASP.NET Core MVC Project .................................................................... 13
Adding the Controller ............................................................................................................................ 17
Understanding Routes .......................................................................................................................... 19

vii
■ CONTENTS

Rendering Web Pages .................................................................................................... 20


Creating and Rendering a View ............................................................................................................ 20
Adding Dynamic Output ........................................................................................................................ 23

Creating a Simple Data-Entry Application ...................................................................... 25


Setting the Scene ................................................................................................................................. 25
Designing a Data Model........................................................................................................................ 26
Creating a Second Action and a Strongly Typed View........................................................................... 27
Linking Action Methods ........................................................................................................................ 28
Building the Form ................................................................................................................................. 30
Receiving Form Data ............................................................................................................................ 31
Displaying the Responses..................................................................................................................... 36
Adding Validation .................................................................................................................................. 38
Styling the Content ............................................................................................................................... 45

Summary ........................................................................................................................ 51
■Chapter 3: The MVC Pattern, Projects, and Conventions ..................................... 53
The History of MVC ......................................................................................................... 53
Understanding the MVC Pattern ..................................................................................... 53
Understanding Models .......................................................................................................................... 54
Understanding Controllers .................................................................................................................... 54
Understanding Views ............................................................................................................................ 55
The ASP.NET Implementation of MVC ................................................................................................... 55

Comparing MVC to Other Patterns.................................................................................. 55


Understanding the Smart UI Pattern ..................................................................................................... 56
Understanding the Model-View Architecture ........................................................................................ 57
Understanding Classic Three-Tier Architectures .................................................................................. 57
Understanding Variations on MVC ........................................................................................................ 58

Understanding ASP.NET Core MVC Projects.................................................................... 59


Creating the Project .............................................................................................................................. 59
Understanding MVC Conventions ......................................................................................................... 62

Summary ........................................................................................................................ 64

viii
■ CONTENTS

■Chapter 4: Essential C# Features......................................................................... 65


Preparing the Example Project ....................................................................................... 65
Enabling ASP.NET Core MVC ................................................................................................................. 67
Creating the MVC Application Components .......................................................................................... 68

Using the Null Conditional Operator ............................................................................... 70


Chaining the Null Conditional Operator ................................................................................................ 71
Combining the Conditional and Coalescing Operators ......................................................................... 72
Using Automatically Implemented Properties ................................................................ 73
Using Auto-Implemented Property Initializers ...................................................................................... 74
Creating Read-Only Automatically Implemented Properties................................................................. 75

Using String Interpolation............................................................................................... 76


Using Object and Collection Initializers .......................................................................... 77
Using an Index Initializer ...................................................................................................................... 79

Using Extension Methods ............................................................................................... 80


Applying Extension Methods to an Interface ........................................................................................ 82
Creating Filtering Extension Methods ................................................................................................... 83

Using Lambda Expressions ............................................................................................ 85


Defining Functions ................................................................................................................................ 86
Using Lambda Expression Methods and Properties ............................................................................. 89

Using Type Inference and Anonymous Types .................................................................. 91


Using Anonymous Types ....................................................................................................................... 92

Using Asynchronous Methods ........................................................................................ 94


Working with Tasks Directly ................................................................................................................. 94
Applying the async and await Keywords .............................................................................................. 96

Getting Names ................................................................................................................ 97


Summary ........................................................................................................................ 99

ix
■ CONTENTS

■Chapter 5: Working with Razor ......................................................................... 101


Preparing the Example Project ..................................................................................... 102
Defining the Model ............................................................................................................................. 103
Creating the Controller ....................................................................................................................... 103
Creating the View ............................................................................................................................... 104

Working with the Model Object .................................................................................... 105


Using View Imports ............................................................................................................................. 107
Working with Layouts ................................................................................................... 109
Creating the Layout ............................................................................................................................ 109
Applying a Layout ............................................................................................................................... 111
Using a View Start File ........................................................................................................................ 112

Using Razor Expressions .............................................................................................. 114


Inserting Data Values .......................................................................................................................... 115
Setting Attribute Values ...................................................................................................................... 117
Using Conditional Statements ............................................................................................................ 118
Enumerating Arrays and Collections ................................................................................................... 120

Summary ...................................................................................................................... 122


■Chapter 6: Working with Visual Studio .............................................................. 123
Preparing the Example Project ..................................................................................... 123
Creating the Model ............................................................................................................................. 124
Creating the Controller and View ........................................................................................................ 126

Managing Software Packages ...................................................................................... 128


Understanding NuGet.......................................................................................................................... 128
Understanding Bower ......................................................................................................................... 130

Understanding Iterative Development .......................................................................... 134


Making Changes to Razor Views ........................................................................................................ 134
Making Changes to C# Classes .......................................................................................................... 136
Using Browser Link............................................................................................................................. 144

x
■ CONTENTS

Preparing JavaScript and CSS for Deployment ............................................................ 150


Enabling Static Content Delivery ........................................................................................................ 150
Adding Static Content to the Project................................................................................................... 151
Updating the View............................................................................................................................... 153
Bundling and Minifying in MVC Applications ...................................................................................... 154

Summary ...................................................................................................................... 158


■Chapter 7: Unit Testing MVC Applications ......................................................... 159
Preparing the Example Project ..................................................................................... 160
Enabling the Built-in Tag Helpers ....................................................................................................... 160
Adding Actions to the Controller ......................................................................................................... 160
Creating the Data Entry Form ............................................................................................................. 161
Updating the Index View ..................................................................................................................... 162

Unit Testing MVC Applications ...................................................................................... 163


Creating a Unit test Project ................................................................................................................. 164
Writing and Running Unit Tests........................................................................................................... 167
Isolating Components for Unit Testing ................................................................................................ 171

Improving Unit Tests ..................................................................................................... 179


Parameterizing a Unit Test .................................................................................................................. 179
Improving Fake Implementations ....................................................................................................... 183

Summary ...................................................................................................................... 189


■Chapter 8: SportsStore: A Real Application ....................................................... 191
Getting Started ............................................................................................................. 192
Creating the MVC Project .................................................................................................................... 192
Creating the Unit Test Project ............................................................................................................. 197
Checking and Running the Application ............................................................................................... 199

Starting the Domain Model........................................................................................... 200


Creating a Repository ......................................................................................................................... 200
Creating a Fake Repository ................................................................................................................ 201
Registering the Repository Service .................................................................................................... 201

xi
■ CONTENTS

Displaying a List of Products ........................................................................................ 202


Adding a Controller ............................................................................................................................. 204
Adding and Configuring the View ....................................................................................................... 205
Setting the Default Route ................................................................................................................... 207
Running the Application...................................................................................................................... 208

Preparing a Database ................................................................................................... 208


Installing Entity Framework Core ....................................................................................................... 209
Creating the Database Classes ........................................................................................................... 210
Creating the Repository Class ............................................................................................................ 212
Defining the Connection String ........................................................................................................... 212
Configuring the Application ................................................................................................................ 213
Creating and Applying the Database Migration .................................................................................. 215

Adding Pagination ........................................................................................................ 216


Displaying Page Links......................................................................................................................... 218
Improving the URLs ............................................................................................................................ 227

Styling the Content ....................................................................................................... 228


Installing the Bootstrap Package ........................................................................................................ 229
Applying Bootstrap Styles to the Layout ............................................................................................. 229
Creating a Partial View ....................................................................................................................... 232

Summary ...................................................................................................................... 234


■Chapter 9: SportsStore: Navigation ................................................................... 235
Adding Navigation Controls .......................................................................................... 235
Filtering the Product List .................................................................................................................... 235
Refining the URL Scheme ................................................................................................................... 239
Building a Category Navigation Menu ................................................................................................ 243
Correcting the Page Count .................................................................................................................. 251

Building the Shopping Cart........................................................................................... 253


Defining the Cart Model ...................................................................................................................... 254
Adding the Add to Cart Buttons .......................................................................................................... 258
Enabling Sessions .............................................................................................................................. 260

xii
■ CONTENTS

Implementing the Cart Controller ....................................................................................................... 261


Displaying the Contents of the Cart .................................................................................................... 264
Summary ...................................................................................................................... 267
■Chapter 10: SportsStore: Completing the Cart .................................................. 269
Refining the Cart Model with a Service ........................................................................ 269
Creating a Storage-Aware Cart Class ................................................................................................. 269
Registering the Service ...................................................................................................................... 270
Simplifying the Cart Controller ........................................................................................................... 271
Completing the Cart Functionality ................................................................................ 272
Removing Items from the Cart ............................................................................................................ 272
Adding the Cart Summary Widget ...................................................................................................... 274

Submitting Orders ........................................................................................................ 277


Creating the Model Class .................................................................................................................... 277
Adding the Checkout Process ............................................................................................................. 278
Implementing Order Processing ......................................................................................................... 282
Completing the Order Controller ......................................................................................................... 285
Displaying Validation Errors ................................................................................................................ 288
Displaying a Summary Page............................................................................................................... 290
Summary ...................................................................................................................... 290
■Chapter 11: SportsStore: Administration .......................................................... 291
Managing Orders .......................................................................................................... 291
Enhancing the Model .......................................................................................................................... 291
Adding the Actions and View .............................................................................................................. 292

Adding Catalog Management ....................................................................................... 295


Creating a CRUD Controller ................................................................................................................. 296
Implementing the List View ................................................................................................................ 298
Editing Products ................................................................................................................................. 299
Creating New Products ....................................................................................................................... 313
Deleting Products ............................................................................................................................... 315

Summary ...................................................................................................................... 318

xiii
■ CONTENTS

■Chapter 12: SportsStore: Security and Deployment .......................................... 319


Securing the Administration Features .......................................................................... 319
Adding the Identity Package to the Project ........................................................................................ 319
Creating the Identity Database ........................................................................................................... 320
Applying a Basic Authorization Policy ................................................................................................. 324
Creating the Account Controller and Views ........................................................................................ 326
Testing the Security Policy.................................................................................................................. 330
Deploying the Application ............................................................................................. 330
Creating the Databases ...................................................................................................................... 331
Preparing the Application ................................................................................................................... 332
Applying the Database Migrations ...................................................................................................... 337
Deploying the Application ................................................................................................................... 337

Summary ...................................................................................................................... 342


■Chapter 13: Working with Visual Studio Code ................................................... 343
Setting Up the Development Environment ................................................................... 343
Installing Node.js ................................................................................................................................ 343
Checking the Node Installation ........................................................................................................... 345
Installing Git........................................................................................................................................ 345
Checking the Git Installation ............................................................................................................... 345
Installing Yeoman, Bower, and Gulp .................................................................................................... 346
Installing .NET Core ............................................................................................................................ 346
Checking the .NET Core Installation ................................................................................................... 347
Installing Visual Studio Code .............................................................................................................. 348
Checking the Visual Studio Code Installation ..................................................................................... 348
Installing the Visual Studio Code C# Extension................................................................................... 349

Creating an ASP.NET Core Project ................................................................................ 350


Preparing the Project with Visual Studio Code ............................................................. 351
Adding NuGet Packages to the Project ............................................................................................... 352
Adding Client-Side Packages to the Project ....................................................................................... 353
Configuring the Application ................................................................................................................ 355
Building and Running the Project ....................................................................................................... 355

xiv
■ CONTENTS

Re-creating the PartyInvites Application ...................................................................... 356


Creating the Model and Repository .................................................................................................... 356
Creating the Database ........................................................................................................................ 359
Creating the Controllers and Views .................................................................................................... 361

Unit Testing in Visual Studio Code ................................................................................ 366


Configuring the Application ................................................................................................................ 366
Creating a Unit Test............................................................................................................................. 367
Running Tests ..................................................................................................................................... 368

Summary ...................................................................................................................... 369


■Part II: ASP.NET Core MVC in Detail ................................................ 371
■Chapter 14: Configuring Applications................................................................ 373
Preparing the Example Project ..................................................................................... 374
Understanding the JSON Configuration Files ............................................................... 376
Configuring the Solution ..................................................................................................................... 377
Configuring the Project ....................................................................................................................... 379

Understanding the Program Class................................................................................ 382


Understanding the Startup Class.................................................................................. 383
Understanding How the Startup Class Is Used ................................................................................... 385
Understanding ASP.NET Services........................................................................................................ 386
Understanding ASP.NET Middleware................................................................................................... 389
Understanding How the Configure Method Is Invoked ....................................................................... 398
Adding the Remaining Middleware Components................................................................................ 407
Using Configuration Data .................................................................................................................... 412

Configuring MVC Services ............................................................................................ 418


Dealing with Complex Configurations .......................................................................... 420
Creating Different External Configuration Files .................................................................................. 420
Creating Different Configuration Methods .......................................................................................... 421
Creating Different Configuration Classes............................................................................................ 422

Summary ...................................................................................................................... 424

xv
■ CONTENTS

■Chapter 15: URL Routing.................................................................................... 425


Preparing the Example Project ..................................................................................... 427
Creating the Model Class .................................................................................................................... 428
Creating the Example Controllers ....................................................................................................... 429
Creating the View ............................................................................................................................... 430

Introducing URL Patterns ............................................................................................. 431


Creating and Registering a Simple Route .................................................................... 433
Defining Default Values ................................................................................................ 434
Defining Inline Default Values ............................................................................................................. 435

Using Static URL Segments .......................................................................................... 437


Defining Custom Segment Variables ............................................................................ 442
Using Custom Variables as Action Method Parameters ...................................................................... 444
Defining Optional URL Segments ........................................................................................................ 446
Defining Variable-Length Routes ........................................................................................................ 448

Constraining Routes ..................................................................................................... 451


Constraining a Route Using a Regular Expression.............................................................................. 454
Using Type and Value Constraints ....................................................................................................... 455
Combining Constraints ....................................................................................................................... 456
Defining a Custom Constraint ............................................................................................................. 457

Using Attribute Routing ................................................................................................ 460


Preparing for Attribute Routing ........................................................................................................... 460
Applying Attribute Routing .................................................................................................................. 461
Applying Route Constraints ................................................................................................................ 464

Summary ...................................................................................................................... 464


■Chapter 16: Advanced Routing Features ........................................................... 465
Preparing the Example Project ..................................................................................... 466
Generating Outgoing URLs in Views ............................................................................. 468
Generating Outgoing Links ................................................................................................................. 468
Generating URLs (and Not Links) ........................................................................................................ 479

xvi
■ CONTENTS

Customizing the Routing System ................................................................................. 480


Changing the Routing System Configuration ...................................................................................... 481
Creating a Custom Route Class .......................................................................................................... 482

Working with Areas ...................................................................................................... 493


Creating an Area ................................................................................................................................. 493
Creating an Area Route ....................................................................................................................... 494
Populating an Area ............................................................................................................................. 495
Generating Links to Actions in Areas .................................................................................................. 497

URL Schema Best Practices ......................................................................................... 499


Make Your URLs Clean and Human-Friendly ...................................................................................... 499
GET and POST: Pick the Right One ...................................................................................................... 500

Summary ...................................................................................................................... 501


■Chapter 17: Controllers and Actions.................................................................. 503
Preparing the Example Project ..................................................................................... 504
Preparing the Views............................................................................................................................ 506

Understanding Controllers............................................................................................ 508


Creating Controllers ..................................................................................................... 508
Creating POCO Controllers .................................................................................................................. 508
Using the Controller Base Class ......................................................................................................... 511

Receiving Context Data ................................................................................................ 512


Getting Data from Context Objects ..................................................................................................... 512
Using Action Method Parameters ....................................................................................................... 517

Producing a Response.................................................................................................. 519


Producing a Response Using the Context Object................................................................................ 519
Understanding Action Results............................................................................................................. 520
Producing an HTML Response ............................................................................................................ 522
Performing Redirections ..................................................................................................................... 531
Returning Different Types of Content .................................................................................................. 538

xvii
■ CONTENTS

Responding with the Contents of Files ............................................................................................... 540


Returning Errors and HTTP Codes ...................................................................................................... 542
Understanding the Other Action Result Classes ................................................................................. 544
Summary ...................................................................................................................... 545
■Chapter 18: Dependency Injection ..................................................................... 547
Preparing the Example Project ..................................................................................... 548
Creating the Model and Repository .................................................................................................... 549
Creating the Controller and View ........................................................................................................ 551
Creating the Unit Test Project ............................................................................................................. 553
Creating Loosely Coupled Components ........................................................................ 554
Examining Closely Coupled Components............................................................................................ 554

Introducing ASP.NET Dependency Injection .................................................................. 561


Preparing for Dependency Injection ................................................................................................... 561
Configuring the Service Provider ........................................................................................................ 562
Unit Testing a Controller with a Dependency ...................................................................................... 564
Using Dependency Chains .................................................................................................................. 565
Using Dependency Injection for Concrete Types ................................................................................. 568
Understanding Service Life Cycles ............................................................................... 570
Using the Transient Life Cycle............................................................................................................. 570
Using the Scoped Life Cycle ............................................................................................................... 574
Using the Singleton Life Cycle ............................................................................................................ 576

Using Action Injection ................................................................................................... 577


Using the Property Injection Attributes......................................................................... 577
Manually Requesting an Implementation Object.......................................................... 578
Summary ...................................................................................................................... 579

xviii
■ CONTENTS

■Chapter 19: Filters ............................................................................................. 581


Preparing the Example Project ..................................................................................... 582
Enabling SSL....................................................................................................................................... 583
Creating the Controller and View ........................................................................................................ 584

Using Filters ................................................................................................................. 586


Understanding Filters ................................................................................................... 589
Getting Context Data ........................................................................................................................... 589
Using Authorization Filters ........................................................................................... 590
Creating an Authorization Filter .......................................................................................................... 591

Using Action Filters ...................................................................................................... 593


Creating an Action Filter ..................................................................................................................... 595
Creating an Asynchronous Action Filter .............................................................................................. 597

Using Result Filters ...................................................................................................... 598


Creating a Result Filter ....................................................................................................................... 599
Creating an Asynchronous Result Filter.............................................................................................. 600
Creating a Hybrid Action/Result Filter................................................................................................. 602

Using Exception Filters ................................................................................................. 604


Creating an Exception Filter ............................................................................................................... 605

Using Dependency Injection for Filters......................................................................... 607


Resolving Filter Dependencies ........................................................................................................... 607
Managing Filter Life Cycles ................................................................................................................ 611

Creating Global Filters .................................................................................................. 614


Understanding and Changing Filter Order .................................................................... 617
Changing Filter Order ......................................................................................................................... 619

Summary ...................................................................................................................... 620


■Chapter 20: API Controllers ............................................................................... 621
Preparing the Example Project ..................................................................................... 622
Creating the Model and Repository .................................................................................................... 622
Creating the Controller and Views ...................................................................................................... 624
Configuring the Application ................................................................................................................ 626

xix
■ CONTENTS

Understanding the Role of RESTful Controllers ............................................................ 628


Understanding the Speed Problem ..................................................................................................... 629
Understanding the Efficiency Problem ............................................................................................... 629
Understanding the Openness Problem ............................................................................................... 630

Introducing REST and API Controllers .......................................................................... 630


Creating an API Controller................................................................................................................... 631
Testing an API Controller..................................................................................................................... 635
Using the API Controller in the Browser.............................................................................................. 639

Understanding Content Formatting .............................................................................. 641


Understanding the Default Content Policy .......................................................................................... 642
Understanding Content Negotiation.................................................................................................... 643
Specifying an Action Data Format ...................................................................................................... 646
Getting the Data Format from the Route or Query String ................................................................... 647
Enabling Full Content Negotiation ...................................................................................................... 648
Receiving Different Data Formats....................................................................................................... 650

Summary ...................................................................................................................... 651


■Chapter 21: Views ............................................................................................. 653
Preparing the Example Project ..................................................................................... 654
Creating a Custom View Engine ................................................................................... 656
Creating a Custom IView .................................................................................................................... 657
Creating an IViewEngine Implementation ........................................................................................... 658
Registering a Custom View Engine ..................................................................................................... 659
Testing the View Engine...................................................................................................................... 660

Working with the Razor Engine .................................................................................... 663


Preparing the Example Project ........................................................................................................... 663
Demystifying Razor Views .................................................................................................................. 665

Adding Dynamic Content to a Razor View .................................................................... 669


Using Layout Sections ........................................................................................................................ 669
Using Partial Views ............................................................................................................................. 675
Adding JSON Content to Views ........................................................................................................... 678

xx
■ CONTENTS

Configuring Razor ......................................................................................................... 680


Understanding View Location Expanders ........................................................................................... 681

Summary ...................................................................................................................... 686


■Chapter 22: View Components .......................................................................... 687
Preparing the Example Project ..................................................................................... 688
Creating the Models and Repositories ................................................................................................ 689
Creating the Controller and Views ...................................................................................................... 691
Configuring the Application ................................................................................................................ 694

Understanding View Components ................................................................................ 695


Creating a View Component ......................................................................................... 696
Creating POCO View Components ....................................................................................................... 696
Deriving from the ViewComponent Base Class................................................................................... 698
Understanding View Component Results ............................................................................................ 699
Getting Context Data ........................................................................................................................... 705
Creating Asynchronous View Components ......................................................................................... 711

Creating Hybrid Controller/View Component Classes .................................................. 714


Creating the Hybrid Views .................................................................................................................. 715
Applying the Hybrid Class ................................................................................................................... 716

Summary ...................................................................................................................... 718


■Chapter 23: Understanding Tag Helpers ............................................................ 719
Preparing the Example Project ..................................................................................... 720
Creating the Model and Repository .................................................................................................... 721
Creating the Controller, Layout, and Views ......................................................................................... 722
Configuring the Application ................................................................................................................ 725

Creating a Tag Helper ................................................................................................... 726


Defining the Tag Helper Class ............................................................................................................. 726
Registering Tag Helpers ...................................................................................................................... 729
Using a Tag Helper .............................................................................................................................. 730
Managing the Scope of a Tag Helper .................................................................................................. 732

xxi
■ CONTENTS

Advanced Tag Helper Features ..................................................................................... 736


Creating Shorthand Elements ............................................................................................................. 736
Prepending and Appending Content and Elements ............................................................................ 739
Getting View Context Data and Using Dependency Injection .............................................................. 743
Working with the View Model ............................................................................................................. 745
Coordinating Between Tag Helpers..................................................................................................... 747
Suppressing the Output Element ........................................................................................................ 749
Summary ...................................................................................................................... 751
■Chapter 24: Using the Form Tag Helpers ........................................................... 753
Preparing the Example Project ..................................................................................... 754
Changing the Tag Helper Registration ................................................................................................ 754
Resetting the Views and Layout ......................................................................................................... 755

Working with Form Elements ....................................................................................... 757


Setting the Form Target ...................................................................................................................... 757
Using the Anti-forgery Feature ........................................................................................................... 758

Working with Input Elements ....................................................................................... 760


Configuring Input Elements ................................................................................................................ 761
Formatting Data Values ...................................................................................................................... 763

Working with Label Elements ....................................................................................... 766


Working with Select and Option Elements ................................................................... 768
Using a Data Source to Populate a select Element............................................................................. 770
Generating Option Elements from an enum........................................................................................ 770

Working with Text Areas ............................................................................................... 775


Understanding the Validation Form Tag Helpers .......................................................... 777
Summary ...................................................................................................................... 777

xxii
■ CONTENTS

■Chapter 25: Using the Other Built-in Tag Helpers .............................................. 779
Preparing the Example Project ..................................................................................... 780
Using the Hosting Environment Tag Helper .................................................................. 781
Using the JavaScript and CSS Tag Helpers .................................................................. 782
Managing JavaScript Files ................................................................................................................. 782
Managing CSS Stylesheets ................................................................................................................. 791

Working with Anchor Elements .................................................................................... 794


Working with Image Elements ..................................................................................... 795
Using the Data Cache ................................................................................................... 796
Setting Cache Expiry .......................................................................................................................... 799
Using Cache Variations ....................................................................................................................... 800

Using Application-Relative URLs .................................................................................. 801


Summary ...................................................................................................................... 804
■Chapter 26: Model Binding ................................................................................ 805
Preparing the Example Project ..................................................................................... 806
Creating the Model and Repository .................................................................................................... 807
Creating the Controller and View ........................................................................................................ 808
Configuring the Application ................................................................................................................ 810

Understanding Model Binding ...................................................................................... 811


Understanding Default Binding Values ............................................................................................... 813
Binding Simple Types ......................................................................................................................... 815
Binding Complex Types ....................................................................................................................... 816
Binding to Arrays and Collections ....................................................................................................... 827

Specifying a Model Binding Source.............................................................................. 834


Selecting a Standard Binding Source ................................................................................................. 835
Using Headers As Binding Sources..................................................................................................... 836
Using Request Bodies as Binding Sources ......................................................................................... 839
Summary ...................................................................................................................... 842

xxiii
■ CONTENTS

■Chapter 27: Model Validation ............................................................................ 843


Preparing the Example Project ..................................................................................... 844
Creating the Model ............................................................................................................................. 846
Creating the Controller ....................................................................................................................... 846
Creating the Layout and Views ........................................................................................................... 847

Understanding the Need for Model Validation .............................................................. 849


Explicitly Validating a Model ......................................................................................... 850
Displaying Validation Errors to the User ............................................................................................. 852
Displaying Validation Messages ......................................................................................................... 855
Displaying Property-Level Validation Messages ................................................................................. 859
Displaying Model-Level Messages ..................................................................................................... 861

Specifying Validation Rules Using Metadata ................................................................ 864


Creating a Custom Property Validation Attribute ................................................................................ 868

Performing Client-Side Validation ................................................................................ 870


Performing Remote Validation ...................................................................................... 872
Summary ...................................................................................................................... 876
■Chapter 28: Getting Started with Identity .......................................................... 877
Preparing the Example Project ..................................................................................... 878
Creating the Controller and View ........................................................................................................ 880

Setting Up ASP.NET Core Identity.................................................................................. 882


Adding the Identity Package to the Application .................................................................................. 882
Creating the User Class ...................................................................................................................... 883
Creating the Database Context Class ................................................................................................. 885
Configuring the Database Connection String Setting ......................................................................... 885
Configuring the Identity Services and Middleware ............................................................................. 887
Creating the Identity Database ........................................................................................................... 888

xxiv
■ CONTENTS

Using ASP.NET Core Identity ......................................................................................... 889


Enumerating User Accounts ............................................................................................................... 889
Creating Users .................................................................................................................................... 892
Validating Passwords ......................................................................................................................... 896
Validating User Details........................................................................................................................ 904

Completing the Administration Features ...................................................................... 910


Implementing the Delete Feature ....................................................................................................... 911
Implementing the Edit Feature ........................................................................................................... 912

Summary ...................................................................................................................... 917


■Chapter 29: Applying ASP.NET Core Identity ...................................................... 919
Preparing the Example Project ..................................................................................... 919
Authenticating Users .................................................................................................... 920
Preparing to Implement Authentication .............................................................................................. 923
Adding User Authentication ................................................................................................................ 926
Testing Authentication ........................................................................................................................ 928

Authorizing Users with Roles ....................................................................................... 929


Creating and Deleting Roles ............................................................................................................... 930
Managing Role Memberships ............................................................................................................. 935
Using Roles for Authorization ............................................................................................................. 941

Seeding the Database .................................................................................................. 945


Summary ...................................................................................................................... 948
■Chapter 30: Advanced ASP.NET Core Identity .................................................... 949
Preparing the Example Project ..................................................................................... 949
Adding Custom User Properties ................................................................................... 951
Preparing for Database Migration ...................................................................................................... 954
Testing the Custom Properties............................................................................................................ 955

Working with Claims and Policies ................................................................................ 956


Understanding Claims ........................................................................................................................ 956
Creating Claims .................................................................................................................................. 961

xxv
■ CONTENTS

Using Policies ..................................................................................................................................... 964


Using Policies to Authorize Access to Resources ............................................................................... 970
Using Third-Party Authentication.................................................................................. 976
Registering the Application with Google ............................................................................................. 976
Enabling Google Authentication .......................................................................................................... 977

Summary ...................................................................................................................... 982


■Chapter 31: Model Conventions and Action Constraints ................................... 983
Preparing the Example Project ..................................................................................... 983
Creating the View Model, Controller, and View ................................................................................... 985

Using the Application Model and Model Conventions .................................................. 987


Understanding the Application Model ................................................................................................. 988
Understanding the Role of Model Conventions................................................................................... 992
Creating a Model Convention.............................................................................................................. 993
Understanding Model Convention Execution Order ............................................................................ 998
Creating Global Model Conventions .................................................................................................... 999
Using Action Constraints ............................................................................................ 1001
Preparing the Example Project ......................................................................................................... 1001
Understanding Action Constraints .................................................................................................... 1003
Creating an Action Constraint ........................................................................................................... 1004
Resolving Dependencies in Action Constraints................................................................................. 1009

Summary .................................................................................................................... 1012

Index ................................................................................................................... 1013

xxvi
About the Author

Adam Freeman is an experienced IT professional who has held senior positions in a range of companies,
most recently serving as chief technology officer and chief operating officer of a global bank. Now retired, he
spends his time writing and long-distance running.

xxvii
About the Technical Reviewer

Fabio Claudio Ferracchiati is a senior consultant and a senior analyst/developer using Microsoft
technologies. He works for Brain Force (www.bluarancio.com). He is a Microsoft Certified Solution
Developer for .NET, a Microsoft Certified Application Developer for .NET, a Microsoft Certified Professional,
and a prolific author and technical reviewer. Over the past ten years, he’s written articles for Italian and
international magazines and coauthored more than ten books on a variety of computer topics.

xxix
PART I

Introducing ASP.NET Core MVC

ASP.NET Core MVC is a radical shift for web developers using the Microsoft platform. It emphasizes
clean architecture, design patterns, and testability, and it doesn’t try to conceal how the Web works.
The first part of this book is designed to help you understand broadly the foundational ideas of
MVC development, including the new features in ASP.NET Core MVC, and to experience in practice
what the framework is like to use.
Another Random Scribd Document
with Unrelated Content
Receivers closed: this being mollifyed with a wet cloth applyed to it,
may again be separated, and taken off, as that also with which salt
is mixed: but the other Lutes that want salt will not be separated, by
reason whereof glasses oftentimes are broken. Wherefore in defect
of the Caput mortuum of Vitriol, temper the clay and sand with
brine: But many mix the filings of iron, powdered glass, flints, &c.
but you need not them for the building of the Furnaces, but only for
the coating of certain glasses used for separation, and distillation,
because the filings of iron being helped with salt, binds, and joins
together most strongly.

Of the closing of the Joints, hindering the evaporation of subtle


Spirits.

T he aforesaid Lute is sufficient for the closing of the Joints of the


first Furnace, where air is not kept from the Spirits, but not of
the Vessels of the second Furnace, where most subtle Spirits are
distilled, which it cannot retain, penetrating the same with the loss
of the better part: wherefore you must make choice of another;
unless upon the other being well dryed, a mixture made of quick
Lime, most subtilly powdered, and Linseed-oyl, besmeared over with
a pencil, which the porous clay attracting to it, is fortifyed, so as to
be able to retain those most subtle Spirits: but this Lute can hardly
be separated again; because refusing water, it cannot be mollifyed;
wherefore the clay is to be tempered only with the white of eggs,
and to be applyed with linnen clouts: but you must prevent the
burning of the linnen, by reason of the extream heat of the neck of
the Receiver, by putting between an iron or strong glass, viz. betwixt
the receiver and the retort. The joints also may be closed with oxe
bladders wet in the white of eggs, also with starch tempered with
water, if it be sometimes applyed, being smeared on paper. For by
this means those most subtile spirits are easily retained, but not
corrosive, for which use the caput mortum of aqua fortis is more
convenient which after it is dryed must be smeared over with a
mixture made of linseed oyl, and quick lime.
And divers kinds of these lutes are had being destined to divers
uses.

Another Lute for broken Glasses.

I t happens sometimes that glass vessels, as receivers, and retorts,


have some cracks, but otherwise are whole and sound; which
are greater in those glasses that do again suffer the heat of the Fire,
wherefore at last the glasses are broken, which if you will prevent,
make a liniment or thin lute of linseed oyl, quick lime, and red lead;
which being smeered over a linnen cloth apply to the crack, upon
which being dryed apply another: but if the crack be very great, you
may apply three or four linen cloths, for the greater safety sake: as
you may apply the whites of egges beaten together, upon the cracks
with linnen, and cast upon it quick lime sifted very fine, and press it
down hard with your hand: which being done, you may apply over
them more linen clouts wet in the whites of eggs, and cast upon
them quick lime again: which when the lute is well dryed, retaines
the spirits, but sooner subject to the corrosion of corrosive spirits
than the former.
Note well that quick lime is not to be mixed with the white of
eggs, and so used upon linen clouts, as the manner of some is;
because the whites of eggs acquire a hardness from the lime before
they be united, and therefore cannot stick, but linen clouts wet First
therewith before the quick lime be cast upon them, so that the lime
doth not immediately touch the glass, being applyed betwixt two
linen cloths.

How those subtile spirits when they are made, may be kept that
they evaporate not.

T hose glasses in which those spirits are kept are for the most part
stopt with cork, or wax, upon which afterward bladders are
bound: which stopping is convenient for some spirits, that do not
prey upon cork or wax: For all corrosive spirits, as of vitriol, Allome,
common salt, nitre, &c. corrode cork, and lixivial spirits, as that of
harts-horn, tartar, salt armoniack, urin, wine, &c. melt wax, and
penetrate it.
And although other stopples might be made, which might retain
both sorts of spirits, yet it would be tedious and laborious to open
those so often, and to stop them again. Wherefore I have found out
a fit kind of glasses, viz. of such, whose mouths have distinctions,
and are fit to receive their covers; as it appears by the delineation.
[See the first figure]. A. signifies the cover: B. the glass containing
the spirit. C. a drawer by the help whereof the spirits are taken out
of the glass, when there is occasion, into the distinction in the brim
of the mouth; viz. of the glass that contains the spirit, is put
quicksilver, and upon this is put a cover; this being done, the
Mercury closeth the joynts of both glasses running in the brim, so
that nothing at all can evaporate: for the spirits do not penetrate the
Mercury, unless they be very corrosive (a thing to be noted) which
then in process of time turn the Mercury into water, but very seldom;
and then the Mercury is to be renewed. But we need not give so
much honour to corrosive spirits, being not to be compared to those
volatile ones, which being abstracted from corrosives not prey upon
Mercury; and much less than these, do lixivial spirits corrode
Mercury; and for the sake of these were these glasses invented, by
the help whereof most subtile spirits are without any loss of their
vertues, if you please, a very long time preserved and kept. And
because when there is occasion the spirits cannot be poured forth by
reason of the Mercury in the brim, you must get a drawer like to
that, by the help whereof wine is taken out of the vessel, but lesser,
having a belly with a little mouth made very accurately. This being
let down you may take up as much as you please, as is needful; the
upper orifice whereof being stopped with the finger nothing drops
out; being put into a lesser glass is thence poured forth for your use.
Then you must again cover the remainder of the spirit that is in the
glass, and as oft as is needful take out with that drawer as much as
is useful. And this is the best way by which the most subtile spirits
are retained; which also are very well retained in those glasses,
whose stoples are of glass smoothed with grinding. But this is a
more costly way of keeping in spirits, and it is done after this
manner.

How glass stopples are to be smoothed by grinding for the


retaining of spirits in their glass vessels.

F irst of all order the matter so that you have glass bottles of
several sorts, some greater, some lesser, with strong necks, and
mouths, with their glass stopples, which being smoothed by grinding
shut the orifice of the bottle very close: Now they are smoothed
thus. Put the stopples in the turn, being set or fastned in some
wood, bring it into a round shape, then being moistned with Smiris,
and water mixed together, let it be put to the mouth of the bottle, so
as to be turned round in the mouth of the bottle, which you must
often take away from the stopples being fastened to the turn, for the
oftner moistening of it, which is with that mixture of prepared Smiris
and water, with the help of a pencil, or feather; and that so often
and so long, until the stopple stop the mouth of the bottle most
closely: which being done, you wipe off the Smiris with a lint from
the stopples and mouth of the bottle, then smeer over the stopple
with a liniment made of some fine washed earth, and water, or oyl,
and again turn it round in the mouth of the bottle, and often smear
it over with this fresh mixture, until the stopple be most exactly
smoothed, which afterward is to be tyed to its proper bottle; the
same also is to be understood concerning the rest, that one may not
be taken for an other, &c. And that you may not need to take away
so much from the stopples, and bottles, get some copper moulds
made for the stopples, which stopples must be taken whilest they be
yet warm, soft, and new drawn from the furnace, that they may be
made of a just roundness, as also other copper moulds. Which must
be put into the mouths of the bottles, whilest they be yet hot and
soft, for the better making of them round, whereby afterwards the
stopple may more easily, and quickly become fit to stop the mouths
of the bottles very close, (as for example: A. is the stopple, B. the
glass or bottle) if thou knowest how to order them rightly, they will
quickly and easily fit one the other.
In defect of a turn, proceed after the following manner, which is
slow, yet safe, because in a turn the glasses, oftentimes waxing hot
are broken by reason of the over great hast; and it is thus, make an
iron or wooden receptacle fit to receive the glass bottle, which being
covered about with linen, and put in, join both parts of the
receptacle warily and softly, with the help of a screw, that the bottle
be not broken, and that that instrument, or receptacle of the bottle
being fastened to a form with the help of the screw, cannot be
moved. Afterwards cause that another wooden instrument be made
for the stopple (as for example, A. the stopple with its receptacle B.
the bottle with its receptacle) that may be separated in the middle,
and be again reunited with a screw after the putting in of the
stopple, which being smeered over with the aforesaid mixture of
smiris and water, take the instrument with both hands, and put the
stopple round about the neck of the bottle, and grind it round upon
the other, as Wine Coopers are used to do in smoothing the taps;
and that so long until the stopple be fit for the bottle; then reitereate
the same labour with the earth tripolis, until it be compleated; and it
will stop as well as a stopple made by the help of a turn [See the
second and third Figures before the fourth part.]
After this manner also you must work those greater glass
receivers of the first furnace, that without luting they may be closed.
Stopples also of vials or Boltheads for fixation may be wrought after
this manner, which in stead of luting may be put into the mouths of
the vials, upon which are put caps of lead; by which means in case
of necessity they may be lifted up, viz. in case the spirits by too
strong a fire be stirred up and rarified, by reason of the danger the
glasses are in to be broken, and may again fall down into the
mouths of the bottles being pressed down with the leaden caps, and
so stop close again. And this way of stopping is better then that
which is done with cork, wax, sulphur, and other things: because in
case the fire be not well governed, and by consequence an errour is
committed, you may preserve your glasses by lifting up of the
stopples, viz. when the spirits are too much stirred up. And although
this be a better way of stopping than the other common way; yet
that which follows is better then this, whereby the spirits are easily
retained, the glasses being preserved, and without all danger of
being broken. And it is thus, viz. get a glass pipe to be made
crooked according to the figure set down, into the belly whereof is
quicksilver to be put from half an ounce to an ounce, or thereabouts,
and let this pipe which hath a belly be put into the vial containing
the matter to be fixed (as for example. A. the pipe with a belly, B. is
the vial, and again C. signifies the aforesaid leaden cap with the
neck of the vial D.) the joints whereof afterwards are to be covered
over with lute, and the vial will never be in danger of being broken.
See the fourth Figure.
These foresaid ways of stopping are the best, by which the
breakings of glasses are prevented, viz. whilest men are in an errour
about the fixing of spirits of salts, minerals and metals, which
although they are fixed with great costs and labours, yet do not
satisfie what is promised and expected, because those kinds of
fixations are violent and forced, and by consequence contrary to
nature: but in the profitable fixation of spirits, not so, where we
must follow Nature, and not commit our selves to fortune in our
labours. For only fools are wont to break their glasses in their
supposed tincture; but Philosophers not so; for every violent thing is
an enemy to Nature; and all the operations of Nature are
spontaneous. They erre therefore, and never shall come unto their
desired end, who attempt violent fixations. I cannot be perswaded
that bodies dead, or half dead can be so mixed together as to
multiply: but I could easily believe that the conjunction of male and
female of one and the same species, sound and nourished with
sound and wholesome meats to be natural, and to make a
spontaneous propagation, and multiplication of their species; viz. of
those that endure in a good, and adverse fortune, in life, and death;
but the conjunction of dead things, to be dead, and barren. Do but
consider how many and various instruments both gold, silver, copper,
iron, tin, and lead; as also earthen, glass, stone, and other vessels of
other materials have been already invented, and found out for the
fixing of Mercury alone with gold and silver, but in vain, because
they have no mutual affinity. For although Mercury adheres to
metals, or metals to it, yet that is not by reason of any affinity for
multiplication, or perfection sake: for it appears by experience that
Mercury flies away in the fire, and leaves the gold, silver and other
metals. Where it is clear that they have no mutual affinity requisite
for the multiplication of metals, nor is it ever possible: For they that
have a mutual affinity embrace one the other and abide together for
ever, although volatile, yet never leave one the other, like gold and
Mercury, when they are united together with the strongest bond, so
that they can never be separated although with the strongest fire.
Wherefore a great care is to be had in the fixation of things joined
together; which if they have a mutual affinity, will embrace and
retain one the other, without the help of any curious glasses with
long necks. Of which things if thou art ignorant, abstain from
medling with them, as being more hurtful then profitable, as dayly
experience both mine own, and others do witness. But that thou
mayst the better understand what things have a mutual affinity one
with the other: attend a little to what I shall say.
Is not he to be laughed at for his folly who will pour rain, or
common water on gold, silver, and other metals to fix them? See
therefore the unwise actions of many covetous Alchymists in so hard
a matter, that spend their time in trifles, reaping according to what
they have sowed, and at last leave off their work which they have
undertaken, after they have expended much cost, and spent their
labour in stenches, watchings, and cares. For I have oftentimes seen
those, that although they have not chosen common water for their
menstruum, yet have made choice of May-dew, snow or rain
gathered in March, and water distilled out of Nostock, or excrement
of Stars; vegetables and animals for their solvent, in which they
have lost their labour.
For as the radical union of the aforesaid things with metals is
impossible: so never is any good to be produced from thence, by
reason of their difference. And such may deservedly be compared to
those, who ascending a very high ladder that hath many steps, doe
presently endeavour to fly from the lowermost to the uppermost;
which is a thing impossible: so neither can there be any conjunction
of things that do so much differ. But as any one may easily ascend
the highest step by degrees, so also any one may (which yet he
need not do) join together extreams, by adding first a thing that is
most near to one of the extreams, and then to this another next to
it, and so by consequence, until you come to the other extream,
which is a thing that requires a very long time, and is a work without
profit. And if things be joined together that have the next affinity,
the one will be delighted in the other, and the one will embrace the
other, will overcome, and retain it. As for example, there is a certain
salt, and that only, that can coagulate, and turn into a body like to it
self, even common water, which can be fixed in a very little time,
with, and by one only certain mineral, which is very volatile. Minerals
also may be fixed by metals, and metals, (a thing which I never yet
tryed) by a certain thing more excellent than metals, without all
doubt. But therefore it is needful in the fixation of minerals to begin
with the coagulation of water, whereby it is turned into salt; and this
afterward into a mineral; which would be too tedious; but it is
sufficient to begin in things most near, in which nature hath begun
to operate, but hath left imperfect; for then there is hope of gain, if
contrary things are not joined together, else not. Behold how ready
Nature is at hand to help any thing that is administred to it, which it
can help: as for example, make salt of calcined Tartar by the help of
solution and coagulation (but do not take that for it, of which a little
before mention hath been made, which is far better than salt of
Tartar) of which after it is calcined, observe the weight; upon which
afterwards pour half the weight of most pure rain water; distilled to
avoid the suspition of impurity; then draw off the water gently in
Balneo, or Sand, which again pour upon the remaining salt of Tartar,
and again draw it off; this do so often as is needful, until all the
water be consumed. Which being done, take out the salt, and weigh
it, being first made red hot in the Fire, and thou shalt find it to be
increased in weight, which increase came from the water, and not
elsewhere.
Note well that the cohobation of the water is to be reiterated often
upon the salt of Tartar. Observe, that by this means, the water is
convertible into salt by Art, &c. And if thou dost not believe the
conversion of things material and corporeal, how wilt thou believe
the conversion of things immaterial, as of the Sun, and Fire into a
material fixed substance; of which thing, something shall be treated
in our Treatise of Aurum potabile, and more at large afterwards in a
Treatise De Generatione Metallorum, if God permit: For you must
know that the circulation of the Elements, and things elementated,
viz. how one is converted into another; and how they nourish and
cherish one the other: as for example, the Earth yields Water, the
Water Air, the Air Fire, and the Fire again Earth; which if it be pure,
yields pure Earth. But that thou maist understand aright how any
thing to be fixed, may be retained by another, by reason of affinity,
observe the following example. The Husbandman casting seed into
the Earth for to multiply, doth not choose any Earth, but that which
is convenient for multiplication, viz. an Earth that is neither too dry,
nor too moist; for the seed cast in sand cannot grow, but is lost: For
whatsoever is to be preserved, is to be preserved by an equal
temper; which, by how much it is more equal or like, so much the
more perfect substance it doth produce. Humidity therefore being
necessarily requisite for the growth of vegetables, without which,
they can neither grow, nor multiply, but the seed being cast into
moist sand, and the Rayes of the Sun acting upon the sand, and
suddenly consuming the humidity thereof, whence follows the
burning up of the seed in the dry sand, because there was no
affinity betwixt the water, and sand; without which, the water could
not be retained by the sand, and consequently, the seed deprived of
its nutriment; it follows necessarily, that some medium be required,
or bond joining and binding the rain, and sand; viz. salt, by the help
whereof, the rain water is retained by the sand, that it be not so
easily consumed by the heat of the sun.
The sand therefore retains the salt, and the salt, the rain water for
the nutrition of the bud: but every salt is not convenient for this
business; for although Christ saith, Luk. Chap. 14, Verse the last,
that earth without salt is barren; yet any common salt is not to be
understood thereby: [See more de Natura Salium.] for some salts,
as common salt, salt of Vitriol, Allome, &c. do not only not do good,
but do hurt to Vegetables, hindering by reason of their dryness their
growth and increase. Now lixivial salts promote them, that which
Country-men do better understand, than our supposed Philosophers:
for they know how to help their barren ground with the excrements
of Animals; which are nothing else but a lixivial salt mixed with
Sulphur, making the earth fat and fertile. And by this means a
vehiculum (rather a bond) is administred to the rain water, that it
may the less be consumed by the heat of the Sun. Moreover, all seed
(consisting in a lixivial salt and sulphur) loves its like, from whence it
borrows its Nutriment, which is observed but by a few Learned or
Unlearned. Husband-Men may well be excused of their ignorance,
because they work only out of Use and Custome. But others that
bear the Title of Learning not so; whose Duty it is to Render a
reason of Germination, who may deservedly be Ashamed of their
Ignorance, being less knowing than Husband-Men. It is manifest,
that Dung makes the Earth Fruitful; but how, and for what reason,
not so; but if it did want nitrous salt, it would neither make it Fertile,
nor promote Germination: for it is not unknown, that Nitre is made
out of the excrements of Animals. The goodness therefore of the
dung consists only in the lixivial salt contained in it, and not in the
straw.
But you will ask perhaps, why doth not any other salt help
Germination? Why is the salt of dung required to Germination, and
no other? We have already answered that, like are helped with like;
and contraries are destroyed by contraries: For experience doth
testify, that every seed consists in a lixivial salt and sulphur, and not
in any acid salt; wherefore also it doth desire and embrace its like.
Let him therefore, that will not believe it, make tryal of the
distillation of the seed of any vegetable; of which, let him force over
a pound by a retort; and he shall see by experience, that not an acid
spirit, but a flegm together with plenty of oyl, and volatile salt
whitening the whole Receiver, comes over; being that which no root
or stalk can do: for the chiefest vertue, odour, and tast of
vegetables, animals, and minerals is found in the seed, in which
thing provident Nature hath done very well, whilest she attributes
the chiefest faculties to the seed, being more obnoxious to injuries
then the rest, which is also preserved, nourished; and cherished by
its like.
Now this discourse which might otherwise have been omitted, was
therefore appointed, that the cause of the germination of vegetables
might be made the more manifest; and that what things have been
spoken of the attraction, and fixation of all things might the better
be understood. The germination therefore, and multiplication of both
minerals, vegetables and animals must be spontaneous, and not
forced, as is that barren and frustraneous of the false Chymists,
because preternatural. Wherefore when you fix any thing be
cautious in the adding of any thing that should retain it, with which
nothing can be fixed. Fire indeed doth always do its office; but it
knows not how to help any preternatural thing; which it doth wholly
destroy, against which nothing can be prevalent, unless it be rightly
ordained according to Nature.
And thus much is spoken for instruction sake, to thee that
intendest to fix any thing, lest otherwise thou losest thy labour.

Of the making of the best crucibles.

T he best crucibles that are requisite for the fourth furnace, not
being found in every place, I thought it worth while to set
down the manner of making them: for I am not ignorant how
oftentimes many for want of these are constrained to be content
with those that are useless, and truly with great loss of metals,
whilest the crucibles are broken in the fire, and consequently with a
tediousness in drawing them out of the ashes.
Chymists have been in a great errour a long time, and not only
they but also goldsmiths, and they that separate metals, as also
others that need the help of crucibles, who perswade themselves
that the best earth that is fit to make the best crucibles is to be
found no where but in Hassia; and therefore with great charges
have caused that Gibsensian crucibles be brought over; not
considering that almost in every place in Germany such earth is to
be found, which indeed is a very great folly of men, proceeding from
the not knowing of good earth which is to be found almost every
where. I do not deny but that the earth of Hassia is very good for
crucibles, tyles, retorts, and other vessels which are to be set in a
very great Fire, for which cause also is commended Gibsensian, and
Waldburgensian crucibles.
A few years since some have made their crucibles, and other
vessels that will endure the fire well, of earth brought out of
England, and France into Holland, which have retained metals very
well in the fire, but not salts, because they are too porous and not
so compact as those of Hassia, wherefore those of Hassia are still
preferred before others, retaining better, metals, and salts. But
although this earth be brought from thence to other places, yet such
strong crucibles could not be made thereof, the cause whereof being
not the constitution of the air, and place to Which some have falsely
imputed it, but an error in the making and burning of them. For in
Hassia there is a great abundance of wood, of which there is no
sparing in the burning the crucibles even to a stony hardness, which
could not be done by a smal Fire of turffes.
The like errour is committed about stone pots, and other vessels
which are made at Frechemium and Siburgus, and other places near
Colen, which are carryed almost through all Europe, the goodness
whereof is ascribed only to the earth, and not to the making. But
now experience hath taught us that any good earth doth become
stony in a violent fire, without respect of the place where it is taken.
Wherefore it is very probable, being a thing possible, that such
vessels are made elsewhere: for every earth being burnt retaining a
white colour, viz. with an indifferent Fire, makes pots, and crucibles
porous, but with a stronger, and with a longer delay, compact like
glass, especially if common salt be cast in a plentiful manner upon
them, being burnt with a very strong fire, because it addes to them
being very well burnt within an external glasy smoothness, by which
means they will be the better able to retain spirits in the Fire.
Wherefore let no man doubt concerning the making the foresaid
vessels of any other earth that is white in burning, with the help of a
very strong Fire: which by how much the greater whiteness it gets in
burning, by so much the better and excellent pots it makes; and
seeing there is a great difference of making crucibles to be set in the
Fire, and of stone pots retaining liquid things, I shall shew the
manner of making both, viz. of stone pots belonging to the first and
second furnace, and of crucibles to the fourth, and thus it is.
He that will try the goodness of white and pure earth, viz. whether
it grows stony in the fire, let him cast a peice of crude earth of the
bigness of a hens egge into a very strong Fire, observing whether it
doth quickly or slowly cleave and break in pieces; which if it doth not
cleave and become powder, although it may have some cracks, is
good earth, and fit for burning, if so be the mixture be well made, in
which lys the art.
The earth that is to be burnt, for pots, receivers, and bottles,
needs no other preparation then that for bricks, which because for
the most part it is too fat, you must mix with it clean sifted fusible
sand, tread it with your feet, and knead it with your hands before
vessels be made thereof; which being made are to be dryed in the
heat of the Sun, or in some other warm place; and being dryed are
to be burnt in a very strong Fire for the space of twenty four or
thirty hours, on which in the mean time you may cast salt if you
please, which being thus burnt do like glass retain easily all liquid
things. But let him that makes crucibles, tyles, bricks and other
vessels appointed for a very strong Fire, use more diligence in the
making of them. And truly first he must beat very small with a
wooden hammer, the earth being dryed well in the Sun, or
elsewhere, and being beaten searse it through a great searse, and
to one part of the sifted earth mix two, three, or four parts (the
fatness of the earth being considered) of the earth burnt in a potters
furnace, and powdered, which being mixed with a sufficient quantity
of water he must tread with his feet, and afterwards knead with his
hands, and the earth will be prepared for the making of vessels, and
when he makes crucibles and tests, let him provide for wooden
moulds both greater and smaller, made in a turn, by the help
whereof they may be made, for the aforesaid vessels cannot be
formed by the usual art of the potters; because the matter of them
must be very lean, appointed for a most strong fire; wherefore
commonly they are made by the help of moulds after the following
manner.
Let a piece of the prepared earth be applyed with your hands to
the mould, which you must hold in one hand, applying and fitting
the earth thereto with the other, or hold it with your legs, that the
earth may be applyed with both your hands. Also you must first rub
the mould very well with clean sifted sand, for else the earth will so
stick to the wooden mould, that a crucible can scarce be taken off
without danger, which being done, it is further fitted by striking it
with a wooden instrument smoothed for the purpose, by which
means the crucible lyes very exactly upon the mould, for by this
means crucibles are made very strong; which being done also let the
crucible be taken off, and set upon a board, and be dryed, first in
the air, then by the heat of the fire, or sun, and then be burned in
the first chamber of our fourth furnace, or in a potters furnace. And
if you intend only to melt metals and not salts, you need not burn
the crucibles if they be well, and exactly made.
Now this caution is to be observed in melting by the help of
crucibles not burnt, that you must give fire above by little and little,
for fear of breaking the crucibles feeling a suddain heat.
Now that they may be made equal in strength, weight, and
thickness, you must weigh one crucible rightly made by the help of
the mould in one scale, and a piece of the prepared earth, which is
to be put into the other scale, and if they be equal in weight, take
out that piece, and put in another; and this do so often, till you be
come to the number of the crucibles which you would have made:
By this means they are made equal, and you need not cut off any
overplus of the earth when it is fitted to the mould, because all are
made equal, by reason of the equal weight of the matter of each of
them, and the work is sooner done then otherwise.
This indeed is the best way but tedious and laborious, wherefore
considering the matter a little more seriously, I found at last that the
following way is far better than the former: whereby not only
stronger crucibles are made, but also more in one hour, then in that
former common way in three or four. Where first, the mould is made
of latten (on which I advise you to apply the earth) signified by the
letter A. viz. that being the best, which is made by the help of
fusion. Then the counter-mould answering this, signified by the
letter B. yet so that that do not enter too deep into this, not
touching the bottom by the distance at least of one fingers breadth;
but in greater crucibles a greater thickness of the bottom is required,
as the practise will teach thee.
Let him therefore that is making crucibles apply the earth to the
mould, as hath been above said in the First manner, which being
done, let him again take off the crucible that is formed or cast, and
set it in the air to be dryed. Then having First made a sufficient
number of crucibles, let him make the mould clean from the earth or
sand, and annoynt it with grease, or oyl Olive taken up with a
sponge, as also the counter-mould, into which let him put the
crucible being half made and dryed, and into this the mould, which
he must strike above twice or twice or thrice with a heavy wooden
mallet, that the earth may be rightly, and exactly applyed to the
mould; which being done let him take off the mould, and turn the
countermould together with the crucible, which let him knock a little
against the form (where the crucibles are made) and let him take in
his hand the crucible falling from thence; which he must afterwards
dry and burn, as hath been above said in the First manner. And by
this way are made the best, and the best proportioned crucibles,
Fixed and smooth, not only for melting of metals, but also for
minerals and salts; the like to which I never yet saw, as being
without all danger, if so be rightly made of the best earth. And that
they may be made equal in weight and strength, they must be
weighed as before hath been said, And this labour is easie and
pleasant, when they are made with ones own hand, and that greater
or lesser at pleasure.
After the same manner also are made tests viz. by the help of the
like kind of moulds, which must not be long but plain like shells as
appears by the annexed Figure, A. and B. Not only tests but also
cuples are made by the help of these moulds. [See the fifth and
sixth Figures.]
Now tests are made more easily this way then crucibles, because
the earth only is weighed, and being handled with the hands is put
into the counter-mould, which then you must with the upper-part
press hard; that it may be made conformable to the mould, viz.
plain, not long, that which may easily therefore be made; and for
this cause those crucibles are easily again taken out, viz. if the
mould be turned, or the counter-mould be a little knocked against
the sides of the form. And if the earth be beaten in too fast that it
goes out at the sides, you must cut it off with a knife, or else the
crucible, or test is hardly taken out, sticking to the brims, which
practise will teach thee. For all things cannot be so accurately
demonstrated by a pen.
And take this for a caution, that thou do not make thy tests and
crucibles of earth that is too soft, but of that which is half dry,
otherwise they are hardly taken out of the moulds; for that is more
easily and rightly applyed to the mould. And if thou proceed rightly
according to the prescript, scarce one crucible of a hundred will be
lost.
This also is to be observed, that the superfluous earth which is cut
off must not be mixed again with the mass for crucibles, because it
is spoyled with the fat, or oyl that is smeared over the moulds, and
therefore cannot be so well mixed again, and being burnt cleaves,
for which cause bad crucibles are made. Wherefore it is to be kept
apart for mending of furnaces that are spoiled with an extraordinary
heat of the Fire; or for covers of crucibles that are to be made by
the help of the hands only, or of moulds, which we cannot want, if
we would work all things exactly.
Now for tyles, and other vessels that serve for distillation, and
melting, they are made by the help of wooden moulds after this
manner. Let the mould be made exactly like to the tyles, and other
vessels, then cut off leaves from the earth being very well prepared,
with a copper wier upon two equal tables of wood, and then a piece
of the earth is to be laid with a knife upon the mould, that it may
there get some hardness; which afterward is to be taken away,
dryed well, and burnt. And if any thing further is to be done, viz. by
cutting off, or adding, it must be done by earth half dryed, or a little
hardened. For by this means any one may get for himself earthen
vessels that are necessary, without much cost or pains for certainty
sake. For those that are sold, are negligently made, in which
oftentimes in the drying, the cracks which are made, are filled up
with some earthen liniment, before they are burnt, which therefore
are not durable in the fire, but are broken, and that oftentimes not
without great loss of the metal, which is again to be gathered out of
the ashes by the help of a tedious washing. It is better therefore to
work those vessels with ones own hand for certainty sake. For not all
and every crucible can alwaies and every where be made equal, and
be of a like durableness in the Fire, though they are made most
diligently: and therefore a consideration being had of their
goodness, they may be used for divers uses, and the better may be
used in the melting of the better metals. But let no man perswade
himself that all these can indifferently hold in the Fire, although they
be the best of all, how many soever you make; for I never yet saw
any earth which could hold litharge in the Fire and salt of Tartar,
because the best that ever I saw is not free from penetration of
them, which is the greatest impediment of some profitable
operations, which therefore are omitted.
And let this which hath been spoken, suffice concerning the
making of crucibles: let every one therefore that hath a care of his
business, use better diligence for the time to come in the making
crucibles for more certainty sake, and he will not repent of his
labour. Now how Tests and Cuples may be exactly applyed to the
aforesaid Molds, is not my work at this time to shew, because many
years since it hath been done by others; especially, by that most
ingenious Man, Lazarus Ercker, whose Writings concerning the
manner of making of Tests and Cuples I cannot mend, to which
Authors I refer the Reader, where he shall find sufficient Instruction
and Information concerning this matter. But there are also other
Tests, of which I shall say nothing in this place, but elsewhere
happily I may, by the help whereof, lead is bettered in tryal if it be
sometimes melted again.

Of the vitrification of Earthen Vessels belonging to the first and


second Furnace.

I n the defect of glass Instruments belonging to our first Furnace,


you may make such as are very useful, of the best Earth, which
being well glazed, or double glazed, are sometimes better than old
Glass; especially, those that are made of Earth that do not drink up
the spirit, such as is found almost every where, which becomes
stony being burnt: Now the Art of burning hath not hitherto been so
well known, of which something hath been said already, where the
Earth being burnt with a very strong fire, is made so compact, as
that it becomes hard and solid as a stone. The Potters Furnaces
being too weak for this strong burning, there is required a peculiar
Furnace for this Work; in which, the strongest fire for the burning of
them may be made: But because no body thinks to build such an
one, only for some few Vessels not worth the spending of costs and
labours: there is yet another way of vitrifying of any sort of Earth
(red Clay only excepted) not to be slighted if well done; especially, if
the matter vitrifying when it is cold after the burning is ended, doth
not cleave and chop, and it is not hurt by corrosive spirits as the
glass made of lead, retaining spirits, as well subtle as corrosive, as
that white vitrification of the Italians and Hollanders: you must
therefore in defect of a fitting Furnace, wherein Vessels being burnt
become stony, make them of the best Earth, and glaze them with
the best Glass of Tin, but not of Lead; and by how much the more
the calx of Tin goes into the vitrifying mixture, so much the better is
it made; for Tin being reduced into a calx with Lead, hath no more
affinity with corrosive spirits; wherefore it is more fit for vitrification.
But he that will not be at so much costs, let him vitrify with Venice
Glass powdered, which vitrification also is not to be slighted,
requiring a very great heat for the burning, and therefore flowing
with great difficulty in these common Potters Furnaces; wherefore
you must mix some Borax with the Glass, that it may flow so much
the more easily in the Potters Furnace; else you must pour upon the
earthen Vessels being burnt, Water mixt with Glass, so that it the
Glass may stick to them every where exactly, which afterwards being
well dryed, shall be gathered together into one heap artificially, lest
they take up too great a space, like earthen Dishes that are to be
burnt, and afterwards compass them round about every where with
burnt Bricks, an hole being left open above for the casting in of
coals, yet so, that the Bricks be distant from the Vessels the breadth
of an hand, whereby the coals being cast in above, may the more
freely go round about down to the bottom; which space being filled
with dry coals, you must put upon them other living coals, that the
fire being kindled above, may by little and little burn downward and
perform its work; which being so done, the Vessels will be out of all
danger, if so be they are all well dryed.
The fire being kindled and burning, you must cover the hole with
stones, until the fire of its own accord be extinguisht; the coals
being spent and the vessels become cold.
N. B. Now if there be a great heap of vessels, you must first, the
coals being burnt, add fresh coals once more; for else the vessels
being placed in the middle, cannot be sufficiently burnt, nor the
glass sufficiently flow; wherefore caution is required in the governing
of the fire in this manner, where, if all things are rightly done, the
vessels are better and more truly burnt and vitrifyed than in any
common Potters Furnace whatsoever; yet with greater danger to the
vessels than in a Potters Furnace compassed about with walls. But
let him that burns crucibles and other smaller vessels, burn them in
our melting or distilling Furnace, being covered with coals, giving
Fire first above, for so I my self was wont hitherto to burn all my
crucibles, and burn and glaze all other distilling vessels; and this in
defect of fitting Furnaces is the best way of burning and vitrifying,
where in three or four hours space, the vessels are exactly burnt and
vitrifyed. Now the earth that is to be burnt quickly, must be the best,
and durable in the Fire, for fear of breaking of some of the vessels.
Let him therefore in this case for security sake, use our fourth
Furnace, who hath built it with his chambers, in the first wherereof
he may burn and vitrify without any danger. But that foresaid way of
burning and vitrifying, is not to be slighted; wherefore I would have
thee be admonished to be cautious in giving of Fire, that you give no
more or less than you should, lest afterwards you impute the cause
of your errour committed, to me, whilst the vessels are broke as if I
had not wrote the Truth, but to thy self that errest, and must for the
future be more diligent, and cautious in this work.
I know other vitrifications of divers colours hitherto unknown, and
indeed most secret, not to be communicated to every one
indifferently: but he that knows how to reduce metals into a true
glass, retaining the colour of its metal, is indeed the inventor of a
very great secret; to whom, if he consider the matter more
profoundly, and exercise himself therein, a Gate is open, with the
blessing of God, to a greater light.
There are also other vitrifications, with which the earth being
covered doth appear, as if it were adorned with Gems; but because
it is not our purpose now to treat of such kinds, I shall make an end
of vitrifications, one only excepted, which I shall communicate for
the sake of the Sick, and Physitians; and it is this:
Make little earthen Cups very smooth and white of the best earth
being burnt: then make the following glasse to flow in a very strong
crucible, in which dip one cup after another, being held with tongs,
and first made red hot in some little Furnace, letting them lye
covered therein for a while, that the earth may the better attract the
glass; which being done, let them be taken out, and be set again
into the foresaid collateral Furnace, where they were before made
red hot, when one is taken out, dip another in the molten glass in its
place, which also is again to be set as the first into the aforesaid
Furnace; and this is to be reiterated so often, until all the pots be
covered over with glass: all which being done, the Furnace is to be
shut close every where, that the wind enter not into it, and so it is to
be left until it become cold of it self, and the glass covering over the
cups remain intire, which otherwise cannot be if the cups be set in a
cold place; now the glass is made after this manner.
Take of crude Antimony two parts, of pure Nitre one part; grind
them well being mixt together, kindle the mixture being put into a
crucible with a red hot iron, and the Sulphur of Antimony will be
burnt together with the Nitre, a mass of a brown colour being left
behind, which you must take out while it is hot with a spatle that it
may cool, which afterwards being melted in another strong crucible
for the space of half an hour, or an hour, makes that glass with
which the aforesaid cups with their covers are covered over.

Of the use of the aforesaid Cups.

T here is no one that can deny that Antimony is the most excellent
of all vomitives, wherefore, so many and so various
preparations have been invented by Physitians for the taking away of
the malignity thereof; whereof I have shewed some, together with
the use thereof in the First and Second Part of this Book, where
alwaies one is better than another; yet notwithstanding ’tis confest,
that Antimony reduced into Glass, is sufficient to purge the Stomack
and Bowels from all corrupt Humors, and that without all danger,
(being rightly administred) as well by vomit as by stool, by which
means many grievous imminent Diseases are not only prevented,
but also presently are cured.
But you infer, that this is yet a crude and imperfect preparation,
and therefore not so safe. To which I answer, that Antimony that
purgeth, needeth no preparation, for if all the crudity thereof were
wholly taken away by fixation, it would no more cause vomiting or
stools; wherefore the aforesaid glass of Antimony is not to be
feared, because it is not dangerous, but may safely be given to
Children that are one or two years old, but not in form of a powder,
but in infusion or extraction of its chiefest vertue made with honey,
sugar and wine, sweet or sowre. After which manner being given, it
attracts from all the bowels all vitious humours, and evacuates them
as well upward as downward, without danger; of which thing
elsewhere more at large. Let him that useth the aforesaid Cups,
infuse one or two ounces of wine, and set them a whole night in
some warm place, and the wine will attract from the glass so much
as doth suffice it, which afterwards being drank in a morning, doth
perform the same as an infusion made with the powder of Stibium;
and this is a more delicate way than the other, because a Cup is sent
to the Patient that he may infuse in it the space of a night, two or
three spoonfuls of proper wine, placeing it in some warm place,
which he may drink up blood warm in the morning, with a due
ordering of himself afterwards: Which, in my judgment is a more
delicate way, being made with ones one wine, and ones one hand,
than that tedious way of potions, both large, bitter, and nauseous.
And this Cup may oftentimes be used, and if at length the wine
should not attract sufficiently, the Cup with the wine is to be set in
seething hot water for a little time, that the wine might the better
attract, and work, when need shall require. Now he that gives such
kind of Cups to others, must instruct them concerning the ordering,
and administring of the same. One Cup is sufficient for the Master of
a Family, with his whole Family for all the daies of their life. It is not
to be used by all, and every one, and in all Diseases indifferently, but
only by those that are strong and young; and where the principal
parts are not hurt. Cups may also after another way be covered over
with Glass without Antimony, as follows.
Sublime Auripigmentum in a Glass or Earthen Gourd; and take the
gallant golden coloured Flowers thereof, which being after a peculiar
manner melted, yield a red and most beautiful Glass almost like an
Oriental Ruby, which being broken in pieces, may be used in stead of
an Ornament; but this is more soft, and brittle, than Glass of
Antimony. This Glass, or those Flowers of Auripigmentum, which are
not yet reduced into Glass, do notably glaze the aforesaid Cups with
a red beautiful Colour.
He therefore that will vitrify the aforesaid Cups, must first heat
them red hot in a Fire made with Coals; and being thus hot, dip
them in the aforesaid melted Flowers, and being taken out thence,
put them under an earthen, or iron red hot vessel, and there let
them cool which do perform the same things as those which are said
of the Antimonial Cups.
These Cups are not dangerous, as to be feared, because as
Antimony is corrected by calcination, so Auripigmentum is by
sublimation: from which, if all the malignity be taken away either by
Fire, or by nitre, the vomitive vertue is taken away, as afterward
shall be demonstrated more at large in these five parts, when they
shall come forth again with enlargements, viz. what purging things
are, and how they put forth their vertues, a consideration being had
of their malignity.
There are also other ways of vitrification, and indeed very fine,
and most desireable by all, if they should be communicated; but
because it is not now my purpose to treat here of mechanical things,
but only of some particular vitrifications of vessels belonging to our
furnaces, I am resolved to omit them at this time, and make an end
of these things. I am resolved, God willing, to set forth these parts
more corrected, and in a larger manner, where many excellent things
now omitted for some reasons, shall be published, and
communicated.
Wherefore I will now put an end to this fifth part, where although
I might have added something that is singular concerning artificial
furnaces, yet because time will not now permit, it shall be deferred
to another time and place, where we shall treat further of the
examining, trying and separation of metals: For the best way of
melting of metals in a greater quantity hath not yet been known:
And although they that deal in minerals perswade themselves of the
perfection of their art, yet I can demonstrate an easier, and more
compendious way of melting of metals in a shorter time, in a greater
quantity, and with less costs and pains. Of which more at large
elsewhere, wherefore (Courteous Reader) be contented with these
things, and if I shall see that these few things shall be acceptable to
thee, I will sometime hereafter for thy sake and to thy profit
communicate wonderful secrets which the world will not believe, and
which hitherto are hid, either out of envy or ignorance.
F I N I S.
A N
A P P E N D I X.

T
wo years since I began to publish my new invented furnaces
where also there was mention made of some secrets, which
though I thought never to divulge; yet nevertheless I
underwent many troubles for the communicating of them. Wherefore
I beseech every body that they would no more create troubles to me
or to themselves by their petitions or writings, because for certain
causes I shall for the future communicate nothing but those things
which follow. Expect therefore patiently the time of another Edition,
when these five parts shall come forth more corrected and enlarged,
and many most choice secrets shall be communicated, which were
for certain causes omitted in the first Edition.
I shall now God willing communicate those things which follow,
yet upon this condition (because many are such, that by means
thereof thou maist with a good conscience, without hurt to thy
neighbour, through Gods blessing, get great riches) that thou be
mindful of the poor, and a good steward of riches got honestly, and
use them to the glory of God and the eternal salvation of thy soul.
The preparation of corn, as of Barley, Wheat, Oates, &c. of Apples,
Pears, Cherries, &c., where fermentation being made they do yield
by way of distillation a pure spirit very like to the spirit of wine
without great costs; of the remainders whereof if the matter were
corn, may be made good beer, or vinegar; but if the matter were
any kinde of fruit, as apples, pears, a very good drink like to wine,
so that by this means thou maist find a double profit, by which thou
maist not only have whereby to live honestly, but also to lay up for
thy heirs.
An excellent and wholesome drink of fruit, and corn, that is
durable and like to Spanish, French, and Rhenish wine.
A distillation of the Aqua vitæ of certain vulgar things not costly
and like to the Aqua vitæ of French and Rhenish wine.
A preparation of sugar like to the Western, and of tartar like to the
natural Rhenish, out of honey and not costly; where one pound of
sugar doth not exceed the price of eight or ten stivers, and a pound
of tartar, that doth not exceed the price of two stivers.
A peculiar purification of crude tartar without loss, and a reduction
of it into great crystals not costly, so as the price of one pound doth
not exceed six stivers.
The taking away of the ingrateful tast and odour of honey so as
afterwards there may be made from thence a certain good Aqua
vitæ retaining no more the smell and taste of honey: also a very
good Mead or Methegline like unto very good wine, with which the
same things may be done as with the best wine.
A preparation of Mead out of raisins, great and small, very like in
all things to Spanish wine; out of which also is made a very good
vinegar without great costs.
A preparation of wine and good vinegar of wild grapes.
Durable and wholesome drinks of gooseberries, barberries,
mulberries, strawberries, and the like.
The mending of troubled acid musty wines, &c.
The preparation of a very good vinegar out of certain vegetables
which are to be found every where, which may be compared to that
which comes out of France, and in a great abundance, whereof two
rundlets of nine Gallons do not exceed the price of one Royal. [A
Royal or Imperial is 4 s. 6 d.]
The promoting of the ripening of wines of the cold countries of
Europe (a very few that are very cold being exempted) that they
may yield very good sweet and durable wines, whereas otherwise
they could come to no maturity, being very like to those which hotter
countries yield.
A certain secret way of carrying wines from mountainous places,
where carts, ships, and other commodities are wanting, where the
carrying of ten pipes, doth not exceed the price of one pipe
otherwise carryed, so that by this means, outlandish wines may be
brought to any place with great profit.
A very good and easie preparation of verdegrease out of copper,
whereof one pound doth not exceed the price of six stivers.
A new and compendious distillation of vinegar, of which a rundlet
of eighteen gallons doth not exceed the price of half a ryal, with
which many things may be done, especially the crystallizing of
verdegrease, of which one pound prepared after this manner, doth
not also exceed the price of half a Royal.
A compendious and very easie way of distilling a very strong spirit
of urin, and that without any cost and pains, so that twenty or thirty
pints shall not exceed the price of one royal, being very excellent in
medicine, Alchimy and Mechanique affairs, by the help whereof a
most beautiful blew vitriol may be made out of copper, being very
profitable in Alchimy and medicine, making silver so fusible, that by
the help thereof, glass vessels, as basons, dishes, and candlesticks,
&c. may be so guilded as to be taken for silver.
A way of distilling the spirit of salt in a great quantity, and that
with small costs, so that one pound thereof will scarce exceed the
price of six stivers being very excellent in Alchymy, Medicine, and
other Arts; especially for the doing of these following things, viz. the
separation of gold from silver without hurt to the Cups or other
things, also the solution and separation of gold mixt with copper and
silver by the force of precipitation, where the Menstruum that is
preserved, may again be used for the same uses, which separation is
the easiest of all other humid separations, whereby gold is reduced
to the highest degree.
The separation of volatile sparkling gold out of sand, &c. very
profitable, without which otherwise it could never be separated,
neither by the help of Washing, nor by Mercury, nor by the force of
Melting.
An artificial secret, and hitherto unheard of, trying of stubborn
Metals, finding out their Contents, which otherwise could not be
found out: for oftentimes there are found golden mines, which are
stubborn, in which nothing is found out by the common way, and
therefore they are left unlaboured in, and sometimes elsewhere,
where there are not found Mines of Metals, there are found other
things, as white and red talc, that yield nothing, being tryed the
common way, or very little, all which yet abound with gold and silver,
which may be separated this way.
A new, and unheard of compendious way of melting Mines in
great plenty, where, in the space of one day, by the heat of a certain
separating Furnace, more may be melted than by the common way
in the space of eight daies, where not onely costs are saved, but
also is hope of greater gain.
Another way for the better proving of things melted, and a new
way of separating silver from lead.
A very speedy way of melting Minerals, whereby they are melted
in great plenty, by the help of Pit-coals in defect of other coals.
The fixation of Minerals, Sulphureous, Arsenical, Antimonial; and
others that are volatile, which cannot be retained and melted by the
force of fire, by the help of a certain peculiar furnace with a grate,
so that afterwards they may by infusion yield gold and silver.
The getting of gold and silver, that sparkles, and is rarified, out of
sand, pure clay, flints, &c. by the help of melting.
The separation of gold lying hid in baser minerals and metals most
profitable, which cannot be done the common way.
A very quick Artificial and easie separation of melted gold and
silver by the help of fusion, so that in the space of one day, by the
help of one furnace, some hundreds of Marks may be separated with
far less costs and labour, than by the common way by cement and
Aqua fortis.
The reduction of elaborated gold, of chains and other ornaments
unto the highest degree; also the separation of gold from guilded
silver, by the help of fusion, by which means a hundred marks are
more easily separated than twenty of the common way.
A certain way whereby more silver is separated from lead then by
the Copper.
A separation of good gold from any old iron, which although it be
not a labour of great gain, yet it is sufficient for those who are
contented with a few things.
A separation of gold and silver, from tin or copper, according to
more or less. The maturation of mines, so that they may afterwards
be able to yield more gold and silver, then by the common way, also
the separation of gold and silver out of Antimony, Arsenick, and
Auripigmentum.
The separation of the external sulphur of Venus, that the Son
Cupid may be born.
The separation of silver from the cuples, into which it enters in the
tryal without melting or any other labour or cost.
The preparation of divers earthen things to be done in any part of
the world, like to the Porcellan, that hold fire and retain spirits.
A certain Allome exalting and fixing any colour, especially requisit
for scarlet and other pretious colours, with a certain perpetual
cauldron, that doth not alter colours, and is not costly.
A making of colours for painters, as of purple gum, ultra-marine,
not costly, and especially of that rich white, never before seen, like
to Pearl and Margarites; also a peculiar colouring of gold and silver.
To conclude, I refer the Reader unto the Residue of my Books,
that Treat of those Secrets more plainly; which I am resolved shortly
to put forth.

Those Secrets are all openly taught in the following Treatises, as


in the Explication of Miraculum Mundi, Apology against Farner,
Prosperity of Germany, &c.
F I N I S.
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