Preface |
|
ix | |
Acknowledgments |
|
xi | |
About this book |
|
xii | |
About the author |
|
xv | |
About the cover illustration |
|
xvi | |
|
1 Getting started with Razor Pages |
|
|
1 | (16) |
|
|
2 | (4) |
|
Web development frameworks |
|
|
2 | (2) |
|
|
4 | (1) |
|
Cross-platform functionality |
|
|
5 | (1) |
|
|
5 | (1) |
|
Using your existing knowledge |
|
|
6 | (1) |
|
1.2 What can you do with Razor Pages? |
|
|
6 | (1) |
|
1.3 The technologies that underpin Razor Pages |
|
|
6 | (4) |
|
The ASP.NET Core MVC framework |
|
|
7 | (1) |
|
|
7 | (2) |
|
The design goals of Razor Pages |
|
|
9 | (1) |
|
1.4 When should you use Razor Pages? |
|
|
10 | (1) |
|
1.5 Working with Razor Pages |
|
|
11 | (6) |
|
How do you get Razor Pages? |
|
|
11 | (1) |
|
Choosing a development environment |
|
|
12 | (2) |
|
Choosing a database system |
|
|
14 | (3) |
|
2 Building your first application |
|
|
17 | (33) |
|
2.1 Creating your first website |
|
|
18 | (9) |
|
Creating a website using Visual Studio |
|
|
19 | (1) |
|
Creating a website using the command-line interface |
|
|
20 | (1) |
|
|
21 | (2) |
|
|
23 | (2) |
|
Modifying to include dynamic content |
|
|
25 | (2) |
|
Adding the page to the navigation |
|
|
27 | (1) |
|
2.2 Exploring the project files |
|
|
27 | (8) |
|
The Web Application1.sin file |
|
|
28 | (1) |
|
The Web Application1.csproj file |
|
|
28 | (1) |
|
|
29 | (1) |
|
|
29 | (1) |
|
|
30 | (1) |
|
|
30 | (1) |
|
|
31 | (1) |
|
|
32 | (3) |
|
2.3 Understanding middleware |
|
|
35 | (15) |
|
|
35 | (3) |
|
|
38 | (1) |
|
The application request pipeline |
|
|
39 | (2) |
|
|
41 | (4) |
|
|
45 | (5) |
|
3 Working with Razor Pages |
|
|
50 | (36) |
|
3.1 Working with Razor syntax |
|
|
51 | (11) |
|
Directives and code blocks |
|
|
51 | (3) |
|
Rendering HTML with expressions |
|
|
54 | (1) |
|
|
55 | (2) |
|
Rendering literal strings |
|
|
57 | (1) |
|
|
57 | (5) |
|
|
62 | (6) |
|
Assigning the Layout property |
|
|
64 | (2) |
|
Injecting optional content with sections |
|
|
66 | (2) |
|
3.3 Reusable HTML with partial views, tag helpers, and view components |
|
|
68 | (4) |
|
|
68 | (2) |
|
|
70 | (2) |
|
|
72 | (1) |
|
|
72 | (14) |
|
|
73 | (2) |
|
The PageModel as a view model |
|
|
75 | (3) |
|
The PageModel as a controller |
|
|
78 | (8) |
|
4 Matching URLs to Razor Pages with routing |
|
|
86 | (29) |
|
|
87 | (4) |
|
|
89 | (2) |
|
4.2 Customizing route templates |
|
|
91 | (13) |
|
|
91 | (1) |
|
|
92 | (2) |
|
Binding route data to handler parameters |
|
|
94 | (2) |
|
|
96 | (1) |
|
|
96 | (4) |
|
Creating additional routes |
|
|
100 | (1) |
|
Working with PageRouteModel conventions directly |
|
|
101 | (3) |
|
|
104 | (11) |
|
|
104 | (3) |
|
Using the IUrlHelper to generate URLs |
|
|
107 | (1) |
|
Generating redirect URLs from ActionResults |
|
|
108 | (1) |
|
Customizing URL generation |
|
|
109 | (1) |
|
Using parameter transformers to customize route and parameter value generation |
|
|
110 | (5) |
|
5 Working with forms: Model binding |
|
|
115 | (37) |
|
|
117 | (7) |
|
Using the post-redirect-get pattern |
|
|
117 | (2) |
|
Accessing values from Request.Form |
|
|
119 | (2) |
|
Accessing values from Request Query |
|
|
121 | (3) |
|
|
124 | (16) |
|
Using model binding with handler parameters |
|
|
124 | (1) |
|
Using model binding with public properties |
|
|
125 | (2) |
|
|
127 | (5) |
|
Binding simple collections |
|
|
132 | (2) |
|
Binding complex collections |
|
|
134 | (6) |
|
5.3 Validating user input in Razor Pages |
|
|
140 | (12) |
|
DataAnnotation attributes |
|
|
140 | (2) |
|
|
142 | (4) |
|
|
146 | (1) |
|
Managing more complex validation with ModelState |
|
|
147 | (1) |
|
Custom validation attributes |
|
|
148 | (4) |
|
6 Working with forms: Tag helpers |
|
|
152 | (35) |
|
6.1 The form and form action tag helpers |
|
|
153 | (1) |
|
6.2 Input and label tag helpers |
|
|
154 | (10) |
|
Understanding the input types |
|
|
156 | (4) |
|
Using data annotation attributes to control presentation |
|
|
160 | (1) |
|
Formatting the rendered date or time value |
|
|
161 | (2) |
|
Using the Display Attribute to control labels |
|
|
163 | (1) |
|
6.3 The select tag helper |
|
|
164 | (14) |
|
|
165 | (5) |
|
|
170 | (3) |
|
|
173 | (2) |
|
|
175 | (3) |
|
6.4 Check boxes and radio controls |
|
|
178 | (1) |
|
|
179 | (8) |
|
7 Using dependency injection to manage services |
|
|
187 | (23) |
|
7.1 The reason for dependency injection |
|
|
188 | (7) |
|
Single-responsibility principle |
|
|
188 | (4) |
|
|
192 | (1) |
|
|
193 | (2) |
|
|
195 | (1) |
|
7.2 Inversion of control containers |
|
|
195 | (10) |
|
|
196 | (1) |
|
|
197 | (4) |
|
|
201 | (1) |
|
Other service registration options |
|
|
202 | (1) |
|
Registering multiple implementations |
|
|
203 | (2) |
|
7.3 Other ways to access registered services |
|
|
205 | (5) |
|
|
205 | (1) |
|
|
206 | (1) |
|
Directly from the service container with GetService and GetRequiredService |
|
|
206 | (3) |
|
|
209 | (1) |
|
8 What is Entity Framework Core? |
|
|
210 | (42) |
|
|
210 | (1) |
|
|
211 | (2) |
|
|
213 | (2) |
|
Installing Entity Framework Core |
|
|
215 | (1) |
|
|
216 | (1) |
|
|
217 | (1) |
|
|
218 | (1) |
|
|
219 | (5) |
|
|
220 | (2) |
|
|
222 | (1) |
|
Creating and applying a migration |
|
|
222 | (2) |
|
|
224 | (7) |
|
Retrieving multiple records |
|
|
224 | (3) |
|
|
227 | (4) |
|
8.4 Scaffolding CRUD pages |
|
|
231 | (7) |
|
Visual Studio scaffold instructions |
|
|
232 | (1) |
|
Scaffolding from the command line |
|
|
233 | (2) |
|
Working with the scaffolded pages |
|
|
235 | (3) |
|
8.5 Creating, modifying, and deleting data |
|
|
238 | (14) |
|
|
241 | (4) |
|
|
245 | (7) |
|
9 Managing users with authentication |
|
|
252 | (31) |
|
9.1 Authentication basics |
|
|
253 | (6) |
|
|
253 | (1) |
|
Adding simple authentication |
|
|
254 | (5) |
|
9.2 ASP.NET Core Identity |
|
|
259 | (6) |
|
|
260 | (1) |
|
Configuring the DbContext |
|
|
261 | (1) |
|
|
262 | (3) |
|
|
265 | (18) |
|
Customizing Identity options |
|
|
265 | (3) |
|
|
268 | (1) |
|
Scaffolding and customizing the UI |
|
|
269 | (8) |
|
Enabling email confirmation |
|
|
277 | (4) |
|
|
281 | (2) |
|
10 Controlling access with authorization |
|
|
283 | (34) |
|
10.1 Basic authorization in Razor Pages |
|
|
284 | (6) |
|
Applying simple authorization |
|
|
285 | (5) |
|
Allowing anonymous access |
|
|
290 | (1) |
|
|
290 | (7) |
|
|
291 | (1) |
|
|
292 | (2) |
|
|
294 | (2) |
|
Using policies to apply role checks |
|
|
296 | (1) |
|
10.3 Claims-based authorization |
|
|
297 | (12) |
|
|
298 | (4) |
|
Using policies to enforce claims-based authorization |
|
|
302 | (1) |
|
Using assertions for more complex requirements |
|
|
303 | (1) |
|
Custom authorization requirements and handlers |
|
|
304 | (4) |
|
|
308 | (1) |
|
10.4 Authorizing resources |
|
|
309 | (8) |
|
Creating a requirement and a handler |
|
|
310 | (4) |
|
Applying authorization to the UI |
|
|
314 | (3) |
|
11 Client-side technologies and AJAX |
|
|
317 | (24) |
|
11.1 Choosing your client-side technology |
|
|
318 | (1) |
|
11.2 Calling page handlers from JavaScript |
|
|
319 | (12) |
|
Using a partial page to return HTML |
|
|
319 | (5) |
|
Posting to a page handler |
|
|
324 | (4) |
|
|
328 | (3) |
|
11.3 Minimal request-handling APIs |
|
|
331 | (6) |
|
|
332 | (1) |
|
Parameters in minimal APIs |
|
|
333 | (2) |
|
|
335 | (2) |
|
11.4 CSS Isolation in Razor Pages |
|
|
337 | (4) |
|
12 Troubleshooting your application |
|
|
341 | (28) |
|
12.1 Exception management |
|
|
343 | (4) |
|
The Developer Exception page |
|
|
343 | (2) |
|
ExceptionHandlerMiddleware |
|
|
345 | (2) |
|
|
347 | (6) |
|
|
348 | (2) |
|
StatusCodePages WithReExecute |
|
|
350 | (3) |
|
|
353 | (16) |
|
|
353 | (1) |
|
|
354 | (2) |
|
|
356 | (1) |
|
|
357 | (1) |
|
Formatting the log message |
|
|
358 | (1) |
|
Applying log filter rules |
|
|
358 | (2) |
|
|
360 | (3) |
|
Structured logging with Serilog |
|
|
363 | (6) |
|
13 Protecting your application against external attacks |
|
|
369 | (22) |
|
|
370 | (5) |
|
|
371 | (1) |
|
Using HTTPS in development |
|
|
372 | (2) |
|
Including HSTS in production |
|
|
374 | (1) |
|
13.2 Broken access control |
|
|
375 | (4) |
|
Incorrect security policies |
|
|
375 | (1) |
|
Cross-site request forgery |
|
|
376 | (3) |
|
13.3 Cryptographic failures |
|
|
379 | (5) |
|
|
379 | (2) |
|
Using the PasswordHasher without Identity UI |
|
|
381 | (3) |
|
|
384 | (7) |
|
|
384 | (3) |
|
|
387 | (4) |
|
14 Configuring and publishing your application |
|
|
391 | (30) |
|
14.1 Working with environments |
|
|
392 | (6) |
|
Understanding and managing environments |
|
|
392 | (1) |
|
|
393 | (2) |
|
Registering services conditionally for each environment |
|
|
395 | (1) |
|
The IHostEnvironment service |
|
|
396 | (1) |
|
The environment tag helper |
|
|
397 | (1) |
|
14.2 Application configuration |
|
|
398 | (7) |
|
|
399 | (1) |
|
Accessing configuration settings programmatically by key |
|
|
400 | (1) |
|
Strongly typed app settings |
|
|
401 | (2) |
|
Using the options pattern |
|
|
403 | (1) |
|
Binding directly to POCOs |
|
|
403 | (1) |
|
|
404 | (1) |
|
14.3 Improving performance with caching |
|
|
405 | (7) |
|
|
406 | (3) |
|
In-memory caching with IMemoryCache |
|
|
409 | (3) |
|
14.4 Publishing your application |
|
|
412 | (9) |
|
Self-contained and framework-dependent |
|
|
412 | (1) |
|
|
413 | (1) |
|
Publishing using Visual Studio |
|
|
414 | (7) |
Index |
|
421 | |