预购商品
书目分类
特别推荐
本書主要介紹ASP.NET Core框架核心的部分,即由一個伺服器和若干中介軟體構建的管道。本書共分為5篇:"第1篇初識編程(第1章)”列舉一系列極簡的實例為讀者提供基本的編程體驗,"第2篇基礎框架(第2~13章)”主要介紹了一系列支撐ASP.NET Core的基礎框架,"第3篇承載系統(4~17章)”主要介紹了ASP.NET Core應用的承載流程,"第4篇伺服器概述(8章)”列舉一系列常見的伺服器類型並對它們進行了比較,"第5篇中介軟體(9~30章)”系統地介紹了一系列預定義的中介軟體。
第 1 篇 初識編程 第 1 章 編程體驗 .............................................................................................................. 2 1.1 控制台程式 ........................................................................................................................ 2 1.1.1 構建開發環境 ........................................................................................................ 2 1.1.2 命令列構建 .NET 應用 ......................................................................................... 3 1.2 ASP.NET 應用 .................................................................................................................... 8 1.2.1 launchSettings.json ................................................................................................. 8 1.2.2 Minimal API ......................................................................................................... 11 1.2.3 中介軟體 ................................................................................................................. 13 1.2.4 配置選項 .............................................................................................................. 17 1.2.5 診斷日誌 .............................................................................................................. 19 1.2.6 路由 ..................................................................................................................... 20 1.3 MVC ................................................................................................................................ 21 1.3.1 定義 Controller ..................................................................................................... 21 1.3.2 引入視圖 .............................................................................................................. 22 1.4 gRPC ................................................................................................................................ 24 1.4.1 定義服務 .............................................................................................................. 24 1.4.2 實現和承載 .......................................................................................................... 26 1.4.3 調用服務 .............................................................................................................. 28 1.5 Dapr.................................................................................................................................. 29 1.5.1 構建開發環境 ...................................................................................................... 29 1.5.2 服務調用 .............................................................................................................. 30 1.5.3 狀態管理 .............................................................................................................. 34 1.5.4 發佈訂閱 .............................................................................................................. 38 1.5.5 Actor 模型 ............................................................................................................ 40 第 2 篇 基礎框架 第 2 章 依賴注入(上) ............................................................................................................. 44 2.1 控制反轉 .......................................................................................................................... 44 2.1.1 流程控制的反轉 .................................................................................................. 44 2.1.2 好萊塢法則 .......................................................................................................... 47 2.1.3 流程定制 .............................................................................................................. 47 2.2 IoC 模式 ........................................................................................................................... 48 2.2.1 範本方法 .............................................................................................................. 48 2.2.2 工廠方法 .............................................................................................................. 49 2.2.3 抽象工廠 .............................................................................................................. 51 2.3 依賴注入 .......................................................................................................................... 53 2.3.1 由容器提供物件 .................................................................................................. 53 2.3.2 3 種注入方式 ....................................................................................................... 55 2.3.3 Service Locator 模式 ............................................................................................ 57 2.4 一個簡易版的依賴注入容器 ............................................................................................ 59 2.4.1 編程體驗 .............................................................................................................. 59 2.4.2 設計與實現 .......................................................................................................... 63 2.4.3 擴展方法 .............................................................................................................. 69 第 3 章 依賴注入(下) ............................................................................................................. 73 3.1 利用容器提供服務 ........................................................................................................... 73 3.1.1 服務的註冊與消費 ............................................................................................... 73 3.1.2 生命週期 .............................................................................................................. 76 3.1.3 服務註冊的驗證 .................................................................................................. 79 3.2 服務註冊 .......................................................................................................................... 82 3.2.1 ServiceDescriptor .................................................................................................. 82 3.2.2 IServiceCollection ................................................................................................. 83 3.3 服務的消費 ...................................................................................................................... 87 3.3.1 IServiceProvider ................................................................................................... 87 3.3.2 服務實例的創建 .................................................................................................. 89 3.3.3 生命週期 .............................................................................................................. 91 3.3.4 ActivatorUtilities .................................................................................................. 96 3.4 擴展................................................................................................................................ 101 3.4.1 適配 ................................................................................................................... 101 3.4.2 IServiceProviderFactory ..................................................... 102 3.4.3 整合協力廠商依賴注入框架 ................................................................................. 102 第 4 章 檔案系統 ......................................................................................................... 107 4.1 抽象的檔案系統 ............................................................................................................. 107 4.1.1 樹形層次結構 .................................................................................................... 107 4.1.2 讀取檔內容 .................................................................................................... 109 4.1.3 監控檔的變化 ................................................................................................ 111 4.2 檔與目錄 .................................................................................................................... 112 4.2.1 IChangeToken ..................................................................................................... 113 4.2.2 IFileProvider ....................................................................................................... 114 4.2.3 兩個特殊的檔案系統 ......................................................................................... 116 4.3 物理檔案系統 ................................................................................................................ 119 4.3.1 PhysicalFileInfo .................................................................................................. 119 4.3.2 PhysicalDirectoryInfo ......................................................................................... 120 4.3.3 PhysicalDirectoryContents .................................................................................. 120 4.3.4 NotFoundDirectoryContents ............................................................................... 121 4.3.5 PhysicalFilesWatcher .......................................................................................... 121 4.4 內嵌檔案系統 ................................................................................................................ 123 4.4.1 將專案檔案變成內嵌資源 ................................................................................. 123 4.4.2 讀取資源檔 .................................................................................................... 124 4.4.3 EmbeddedFileProvider ........................................................................................ 125 第 5 章 配置選項(上) ........................................................................................................... 128 5.1 讀取配置資訊 ................................................................................................................ 128 5.1.1 編程模型三要素 ................................................................................................ 128 5.1.2 以“鍵-值”對的形式讀取配置 ........................................................................ 129 5.1.3 讀取結構化的配置 ............................................................................................ 130 5.1.4 將結構化配置直接綁定為物件 .......................................................................... 133 5.1.5 將配置定義在檔中 ......................................................................................... 133 5.1.6 根據環境動態載入設定檔 ............................................................................. 134 5.1.7 配置內容的同步 ................................................................................................ 136 5.2 配置模型 ........................................................................................................................ 137 5.2.1 資料結構及其轉換 ............................................................................................. 137 5.2.2 IConfiguration .................................................................................................... 138 5.2.3 IConfigurationProvider ....................................................................................... 140 5.2.4 IConfigurationSource .......................................................................................... 142 5.2.5 IConfigurationBuilder ......................................................................................... 143 5.2.6 ConfigurationManager ........................................................................................ 143 5.3 配置綁定 ........................................................................................................................ 144 5.3.1 綁定配置項的值 ................................................................................................ 145 5.3.2 綁定複合物件 .................................................................................................... 147 5.3.3 綁定集合 ............................................................................................................ 149 5.3.4 綁定字典 ............................................................................................................ 151 5.4 配置的同步 .................................................................................................................... 152 5.4.1 配置資料流程 ........................................................................................................ 152 5.4.2 ConfigurationReloadToken .................................................................................. 153 5.4.3 ConfigurationRoot .............................................................................................. 153 5.4.4 ConfigurationSection .......................................................................................... 156 5.5 多樣性的配置源 ............................................................................................................. 157 5.5.1 MemoryConfigurationSource .............................................................................. 157 5.5.2 EnvironmentVariablesConfigurationSource ......................................................... 158 5.5.3 CommandLineConfigurationSource .................................................................... 160 5.5.4 FileConfigurationSource ..................................................................................... 163 5.5.5 StreamConfigurationSource ................................................................................ 173 5.5.6 ChainedConfigurationSource ............................................................................... 175 第 6 章 配置選項(下) ........................................................................................................... 177 6.1 Options 模式 ................................................................................................................... 177 6.1.1 將配置綁定為 Options 物件 ............................................................................... 177 6.1.2 提供具名的 Options ........................................................................................... 179 6.1.3 配置源的同步 .................................................................................................... 180 6.1.4 直接初始化 Options 物件 ................................................................................... 182 6.1.5 根據依賴服務的 Options 設置 ........................................................................... 184 6.1.6 驗證 Options 的有效性 ...................................................................................... 186 6.2 Options 模型 ................................................................................................................... 187 6.2.1 OptionsManager ............................................................................... 187 6.2.2 IOptionsFactory ............................................................................... 189 6.2.3 IOptionsMonitorCache ..................................................................... 197 6.2.4 IOptionsMonitor ............................................................................... 198 6.3 依賴注入 ........................................................................................................................ 200 6.3.1 服務註冊 ............................................................................................................ 200 6.3.2 IOptions與 IOptionsSnapshot ......................................... 206 6.3.3 集成配置系統 .................................................................................................... 208 第 7 章 診斷日誌(上) ........................................................................................................... 210 7.1 各種診斷日誌形式 ......................................................................................................... 210 7.1.1 調試日誌 ............................................................................................................ 210 7.1.2 跟蹤日誌 ............................................................................................................ 211 7.1.3 事件日誌 ............................................................................................................ 213 7.1.4 診斷日誌 ............................................................................................................ 216 7.2 Debugger 調試日誌 ........................................................................................................ 219 7.2.1 Debugger ............................................................................................................ 220 7.2.2 Debug ................................................................................................................. 221 7.3 TraceSource 跟蹤日誌 .................................................................................................... 222 7.3.1 跟蹤日誌模型三要素 ......................................................................................... 222 7.3.2 預定義 TraceListener .......................................................................................... 231 7.3.3 Trace .................................................................................................................. 235 7.4 EventSource 事件日誌 .................................................................................................... 237 7.4.1 EventSource ....................................................................................................... 237 7.4.2 EventListener ...................................................................................................... 243 7.4.3 活動跟蹤 ............................................................................................................ 247 7.5 DiagnosticSource 診斷日誌 ............................................................................................ 251 7.5.1 標準的觀察者模式 ............................................................................................ 251 7.5.2 AnonymousObserver .................................................................................... 253 7.5.3 強類型的日誌事件訂閱 ..................................................................................... 256 7.5.4 針對活動的跟蹤 ................................................................................................ 258 第 8 章 診斷日誌(中) ........................................................................................................... 260 8.1 統一日誌編程模式 ......................................................................................................... 260 8.1.1 日誌輸出 ............................................................................................................ 260 8.1.2 日誌過濾 ............................................................................................................ 265 8.1.3 日誌範圍 ............................................................................................................ 271 8.1.4 LoggerMessage ................................................................................................... 273 8.2 日誌模型詳解 ................................................................................................................ 274 8.2.1 日誌模型三要素 ................................................................................................ 274 8.2.2 ILogger ............................................................................................................... 275 8.2.3 ILoggerProvider .................................................................................................. 277 8.2.4 ILoggerFactory ................................................................................................... 277 8.2.5 LoggerMessage ................................................................................................... 281 8.3 日誌範圍 ........................................................................................................................ 283 8.3.1 調用鏈跟蹤 ........................................................................................................ 283 8.3.2 服務範圍堆疊 .................................................................................................... 294 8.3.3 Activity 的應用 .................................................................................................. 296 8.4 依賴注入 ........................................................................................................................ 297 8.4.1 核心服務 ............................................................................................................ 298 8.4.2 配置 ................................................................................................................... 300 8.4.3 日誌過濾規則 .................................................................................................... 303 第 9 章 診斷日誌(下) ........................................................................................................... 306 9.1 控制台 ............................................................................................................................ 306 9.1.1 ConsoleFormatter ................................................................................................ 306 9.1.2 ConsoleLogger .................................................................................................... 313 9.1.3 ConsoleLoggerProvider ....................................................................................... 315 9.1.4 服務註冊 ............................................................................................................ 316 9.2 調試器 ............................................................................................................................ 321 9.2.1 DebugLogger ...................................................................................................... 322 9.2.2 DebugLoggerProvider ......................................................................................... 323 9.3 TraceSource 日誌 ............................................................................................................ 323 9.3.1 TraceSourceLogger ............................................................................................. 323 9.3.2 TraceSourceLoggerProvider ................................................................................ 325 9.4 EventSource 日誌 ........................................................................................................... 327 9.4.1 LoggingEventSource ........................................................................................... 327 9.4.2 EventSourceLogger............................................................................................. 328 9.4.3 EventSourceLoggerProvider ............................................................................... 332 9.4.4 日誌範圍 ............................................................................................................ 334 第 10 章 物件集區 ....................................................................................................... 338 10.1 利用物件集區複用物件 ................................................................................................... 338 10.1.1 對象的“借”與“還” ................................................................................... 338 10.1.2 依賴注入 .......................................................................................................... 340 10.1.3 池化對象策略 .................................................................................................. 340 10.1.4 物件集區的大小 .................................................................................................. 341 10.1.5 對象的釋放 ...................................................................................................... 344 10.2 池化物件管理 .............................................................................................................. 345 10.2.1 IPooledObjectPolicy ................................................................................... 345 10.2.2 ObjectPool ................................................................................................. 346 10.2.3 ObjectPoolProvider ........................................................................................... 351 10.3 擴展應用 ...................................................................................................................... 352 10.3.1 池化集合 .......................................................................................................... 352 10.3.2 池化 StringBuilder ............................................................................................ 354 10.3.3 ArrayPool ................................................................................................... 356 10.3.4 MemoryPool .............................................................................................. 357 第 11 章 緩存 ............................................................................................................. 359 11.1 將資料緩存起來 ........................................................................................................... 359 11.1.1 將資料緩存在記憶體中 ....................................................................................... 359 11.1.2 將資料緩存在 Redis 中 .................................................................................... 360 11.1.3 將資料緩存在 SQL Server 中 ........................................................................... 363 11.2 本地記憶體緩存 ............................................................................................................... 365 11.2.1 ICacheEntry ...................................................................................................... 365 11.2.2 MemoryCacheEntryOptions .............................................................................. 368 11.2.3 IMemoryCache ................................................................................................. 369 11.3 分散式緩存 .................................................................................................................. 378 11.3.1 IDistributedCache ............................................................................................. 378 11.3.2 Redis 緩存 ........................................................................................................ 379 11.3.3 SQL Server 緩存 ............................................................................................... 382 第 12 章 HTTP 調用 ............................................................................................... 385 12.1 HttpClient 的工廠 ......................................................................................................... 385 12.1.1 手動創建 HttpClient ......................................................................................... 385 12.1.2 使用 IHttpClientFactory 工廠 ........................................................................... 387 12.1.3 直接注入 HttpClient ......................................................................................... 387 12.1.4 定制 HttpClient................................................................................................. 388 12.1.5 強類型用戶端 .................................................................................................. 389 12.1.6 失敗重試 .......................................................................................................... 390 12.2 HttpMessageHandler 管道 ............................................................................................. 391 12.2.1 HttpMessageHandler ......................................................................................... 391 12.2.2 DelegatingHandler ............................................................................................ 392 12.2.3 診斷日誌 .......................................................................................................... 396 12.2.4 複用 HttpClientHandler .................................................................................... 398 12.3 HttpClient 的構建 ......................................................................................................... 400 12.3.1 HttpMessageHandlerBuilder ............................................................................. 400 12.3.2 HttpClientFactoryOptions ................................................................................. 401 12.3.3 IHttpMessageHandlerBuilderFilter .................................................................... 407 12.3.4 IHttpClientFactory ............................................................................................ 408 12.4 依賴注入 ...................................................................................................................... 418 12.4.1 基礎服務註冊 .................................................................................................. 418 12.4.2 定制 HttpClient................................................................................................. 420 12.4.3 強類型用戶端 .................................................................................................. 424 第 13 章 資料保護 ............................................................................................ 430 13.1 加密與雜湊 .................................................................................................................. 430 13.1.1 資料加密與解密............................................................................................... 430 13.1.2 設置加密內容的有效期 ................................................................................... 433 13.1.3 撤銷金鑰 .......................................................................................................... 434 13.1.4 “暫態”加解密............................................................................................... 435 13.1.5 密碼雜湊 .......................................................................................................... 437 13.2 加密模型 ...................................................................................................................... 438 13.2.1 IAuthenticatedEncryptor ................................................................................... 438 13.2.2 IKey ................................................................................................................. 439 13.2.3 IKeyRing .......................................................................................................... 440 13.2.4 IKeyRingProvider ............................................................................................. 442 13.2.5 IDataProtector ................................................................................................... 443 13.3 金鑰管理 ...................................................................................................................... 452 13.3.1 KeyManagementOptions ................................................................................... 452 13.3.2 Key ................................................................................................................... 457 13.3.3 IKeyManager .................................................................................................... 459 13.3.4 KeyRingProvider .............................................................................................. 465 13.4 依賴注入 ...................................................................................................................... 472 13.4.1 註冊基礎服務 .................................................................................................. 472 13.4.2 金鑰管理配置 .................................................................................................. 477 13.4.3 擴展配置 .......................................................................................................... 478 附錄 A ......................................................................................................................... 482 第 3 篇 承載系統 第 14 章 服務承載 .............................................................................................. 488 14.1 服務承載 ...................................................................................................................... 488 14.1.1 性能指標收集服務 ........................................................................................... 488 14.1.2 依賴注入 .......................................................................................................... 490 14.1.3 配置選項 .......................................................................................................... 493 14.1.4 承載環境 .......................................................................................................... 496 14.1.5 日誌 ................................................................................................................. 498 14.2 服務承載模型 .............................................................................................................. 500 14.2.1 IHostedService .................................................................................................. 500 14.2.2 IHost ................................................................................................................ 501 14.2.3 IHostBuilder ..................................................................................................... 506 14.3 服務承載流程 .............................................................................................................. 511 14.3.1 服務宿主 .......................................................................................................... 512 14.3.2 服務承載設置 .................................................................................................. 516 14.3.3 創建宿主 .......................................................................................................... 521 14.3.4 靜態類型 Host .................................................................................................. 527 第 15 章 應用承載(上) ......................................................................................................... 531 15.1 管道式的請求處理 ....................................................................................................... 531 15.1.1 承載方式的變遷 .............................................................................................. 531 15.1.2 中介軟體.............................................................................................................. 536 15.1.3 定義強類型中介軟體 ........................................................................................... 539 15.1.4 按照約定定義中介軟體 ....................................................................................... 540 15.2 依賴注入 ...................................................................................................................... 542 15.2.1 服務註冊 .......................................................................................................... 542 15.2.2 服務注入 .......................................................................................................... 544 15.2.3 生命週期 .......................................................................................................... 546 15.3 配置 .............................................................................................................................. 551 15.3.1 初始化配置 ...................................................................................................... 551 15.3.2 以“鍵-值”對形式讀取和修改配置 ............................................................... 552 15.3.3 註冊配置源 ...................................................................................................... 553 15.4 承載環境 ...................................................................................................................... 554 15.4.1 IWebHostEnvironment ...................................................................................... 554 15.4.2 通過配置定制承載環境 ................................................................................... 556 15.4.3 設置監聽位址 .................................................................................................. 559 15.4.4 針對環境的編程............................................................................................... 560 第 16 章 應用承載(中) ......................................................................................................... 564 16.1 中介軟體委託鏈 ............................................................................................................... 564 16.1.1 HttpContext ...................................................................................................... 564 16.1.2 中介軟體 .............................................................................................................. 565 16.1.3 中介軟體管道的構建 ........................................................................................... 566 16.2 伺服器 .......................................................................................................................... 567 16.2.1 IServer .............................................................................................................. 568 16.2.2 針對伺服器的適配 ........................................................................................... 568 16.2.3 HttpListenerServer ............................................................................................ 570 16.3 承載服務 ...................................................................................................................... 573 16.3.1 WebHostedService ............................................................................................ 573 16.3.2 WebHostBuilder ................................................................................................ 573 16.3.3 應用構建 .......................................................................................................... 575 第 17 章 應用承載(下) ......................................................................................................... 577 17.1 共用上下文對象 ........................................................................................................... 577 17.1.1 HttpContext ...................................................................................................... 577 17.1.2 伺服器適配 ...................................................................................................... 580 17.1.3 獲取上下文對象 .............................................................................................. 583 17.1.4 上下文對象的創建與釋放 ............................................................................... 584 17.1.5 RequestServices ................................................................................................ 585 17.2 IServer + IHttpApplication ............................................................................................ 587 17.2.1 IServer .............................................................................................................. 588 17.2.2 HostingApplication ........................................................................................... 588 17.2.3 診斷日誌 .......................................................................................................... 591 17.3 中介軟體委託鏈 .............................................................................................................. 596 17.3.1 IApplicationBuilder .......................................................................................... 596 17.3.2 弱類型中介軟體 .................................................................................................. 599 17.3.3 強類型中介軟體 .................................................................................................. 602 17.3.4 註冊中介軟體 ...................................................................................................... 604 17.4 應用的承載 .................................................................................................................. 604 17.4.1 GenericWebHostServiceOptions ........................................................................ 604 17.4.2 GenericWebHostService .................................................................................... 607 17.4.3 GenericWebHostBuilder .................................................................................... 609 17.4.4 ConfigureWebHostDefaults ............................................................................... 617 17.5 Minimal API ................................................................................................................. 619 17.5.1 WebApplication ................................................................................................ 620 17.5.2 WebApplication 的創建 .................................................................................... 622 17.5.3 工廠方法 .......................................................................................................... 631 第 4 篇 伺服器概述 第 18 章 伺服器 ................................................................................................ 634 18.1 自訂伺服器 .............................................................................................................. 634 18.1.1 IServer .............................................................................................................. 634 18.1.2 請求和回應特性 .............................................................................................. 637 18.1.3 StreamBodyFeature ........................................................................................... 638 18.1.4 HttpListenerServer ............................................................................................ 638 18.2 KestrelServer ................................................................................................................ 642 18.2.1 註冊終節點 ...................................................................................................... 642 18.2.2 限制約束 .......................................................................................................... 652 18.2.3 其他設置 .......................................................................................................... 655 18.2.4 設計與實現 ...................................................................................................... 655 18.3 HTTP.SYS .................................................................................................................... 668 18.3.1 HTTP.SYS 簡介 ................................................................................................ 668 18.3.2 UseHttpSys ....................................................................................................... 669 18.3.3 HttpSysOptions ................................................................................................. 669 18.4 IIS ................................................................................................................................. 672 18.4.1 ASP.NET Core Module ..................................................................................... 672 18.4.2 In-Process 部署模式 ......................................................................................... 672 18.4.3 Out-of-Process 部署模式 .................................................................................. 675 18.4.4 配置 ............................................................................................. 678 第 5 篇 中介軟體 第 19 章 靜態檔 .................................................................................................. 682 19.1 搭建檔案伺服器 ........................................................................................................... 682 19.1.1 發佈物理檔 .................................................................................................. 682 19.1.2 呈現目錄結構 .................................................................................................. 684 19.1.3 顯示預設頁面 .................................................................................................. 685 19.1.4 映射媒體類型 .................................................................................................. 688 19.2 處理檔請求 ............................................................................................................... 690 19.2.1 條件請求 .......................................................................................................... 690 19.2.2 區間請求 .......................................................................................................... 694 19.2.3 StaticFileMiddleware ........................................................................................ 696 19.3 處理目錄請求 ............................................................................................................... 700 19.3.1 DirectoryBrowserMiddleware ........................................................................... 700 19.3.2 DefaultFilesMiddleware .................................................................................... 704 第 20 章 路由 ........................................................................................................... 708 20.1 路由映射 ...................................................................................................................... 708 20.1.1 註冊終節點 ...................................................................................................... 708 20.1.2 設置內聯約束 .................................................................................................. 711 20.1.3 可缺省路由參數............................................................................................... 712 20.1.4 特殊的路由參數............................................................................................... 713 20.1.5 主機名稱綁定 ...................................................................................................... 715 20.1.6 更加自由的定義方式 ....................................................................................... 716 20.2 路由分發 ...................................................................................................................... 717 20.2.1 路由模式 .......................................................................................................... 717 20.2.2 路由終節點 ...................................................................................................... 722 20.2.3 中介軟體.............................................................................................................. 730 20.2.4 處理器適配 ...................................................................................................... 737 20.2.5 Minimal API ..................................................................................................... 746 20.3 路由約束 ...................................................................................................................... 748 20.3.1 預定義的 IRouteConstraint ............................................................................... 749 20.3.2 IInlineConstraintResolver .................................................................................. 750 20.3.3 自訂約束 ...................................................................................................... 750 第 21 章 異常處理 ...................................................................................................... 753 21.1 呈現錯誤資訊 .............................................................................................................. 753 21.1.1 開發者異常頁面 .............................................................................................. 753 21.1.2 定制異常頁面 .................................................................................................. 756 21.1.3 針對回應狀態碼定制錯誤頁面 ........................................................................ 757 21.2 開發者異常頁面 ........................................................................................................... 759 21.2.1 IDeveloperPageExceptionFilter ......................................................................... 759 21.2.2 顯示編譯異常資訊 ........................................................................................... 760 21.2.3 DeveloperExceptionPageMiddleware ................................................................ 764 21.3 異常處理器 .................................................................................................................. 766 21.3.1 ExceptionHandlerMiddleware ........................................................................... 766 21.3.2 IExceptionHandlerPathFeature 特性 ................................................................. 768 21.3.3 清除緩存 .......................................................................................................... 771 21.3.4 404 回應 ........................................................................................................... 772 21.4 回應狀態碼頁面 ........................................................................................................... 774 21.4.1 StatusCodePagesMiddleware............................................................................. 774 21.4.2 阻止處理異常 .................................................................................................. 775 21.4.3 註冊中介軟體 ...................................................................................................... 777 第 22 章 回應緩存 ............................................................................................................ 783 22.1 緩存回應內容 .............................................................................................................. 783 22.1.1 基於路徑的回應緩存 ....................................................................................... 783 22.1.2 引入其他緩存維度 ........................................................................................... 785 22.1.3 緩存遮罩 .......................................................................................................... 790 22.2 HTTP-Cache ................................................................................................................. 791 22.2.1 私有緩存和共用緩存 ....................................................................................... 792 22.2.2 回應的提取 ...................................................................................................... 792 22.2.3 新鮮度檢驗 ...................................................................................................... 793 22.2.4 顯式緩存控制 .................................................................................................. 794 22.3 中介軟體 .......................................................................................................................... 795 22.3.1 緩存上下文對象............................................................................................... 795 22.3.2 緩存策略 .......................................................................................................... 796 22.3.3 緩存鍵 .............................................................................................................. 797 22.3.4 緩存的讀/寫 ..................................................................................................... 798 22.3.5 ResponseCachingMiddleware ............................................................................ 799 22.3.6 註冊中介軟體 ...................................................................................................... 801 第 23 章 會話 ...................................................................................................... 803 23.1 利用會話保留“語境” ............................................................................................... 803 23.1.1 設置和提取會話狀態 ....................................................................................... 803 23.1.2 查看存儲的會話狀態 ....................................................................................... 805 23.1.3 查看 Cookie ...................................................................................................... 807 23.2 會話狀態的讀/寫 .......................................................................................................... 807 23.2.1 ISession ............................................................................................................ 808 23.2.2 DistributedSession ............................................................................................ 809 23.2.3 ISessionStore .................................................................................................... 810 23.3 會話中介軟體 .................................................................................................................. 811 23.3.1 SessionOptions ................................................................................................. 811 23.3.2 ISessionFeature ................................................................................................. 812 23.3.3 SessionMiddleware ........................................................................................... 812 第 24 章 HTTPS 策略 ........................................................................................... 815 24.1 HTTPS 終節點的切換 .................................................................................................. 815 24.1.1 構建 HTTPS 網站 ............................................................................................ 815 24.1.2 HTTPS 重定向 ................................................................................................. 818 24.1.3 流覽器自動重定向 ........................................................................................... 819 24.1.4 HSTS 選項配置 ................................................................................................ 821 24.2 HTTPS 重定向 ............................................................................................................. 823 24.2.1 HttpsRedirectionOptions ................................................................................... 823 24.2.2 HttpsRedirectionMiddleware 中介軟體 ................................................................ 824 24.2.3 中介軟體註冊 ...................................................................................................... 826 24.3 HSTS ............................................................................................................................ 827 24.3.1 HstsOptions ...................................................................................................... 827 24.3.2 HstsMiddleware 中介軟體 .................................................................................... 828 24.3.3 中介軟體註冊 ...................................................................................................... 829 第 25 章 重定向 ................................................................................................... 830 25.1 基於規則的重定向 ....................................................................................................... 830 25.1.1 用戶端重定向 .................................................................................................. 830 25.1.2 服務端重定向 .................................................................................................. 831 25.1.3 IIS 重寫規則 .................................................................................................... 832 25.1.4 Apache 重寫規則 ............................................................................................ 834 25.1.5 HTTPS 重定向 ................................................................................................. 836 25.2 重定向中介軟體 .............................................................................................................. 838 25.2.1 重定向規則 ...................................................................................................... 838 25.2.2 RewriteMiddleware ........................................................................................... 839 25.3 預定義規則 .................................................................................................................. 841 25.3.1 “萬能”規則 .................................................................................................. 841 25.3.2 用戶端重定向 .................................................................................................. 842 25.3.3 服務端重定向 .................................................................................................. 843 25.3.4 WWW 重定向 .................................................................................................. 843 25.3.5 HTTPS 重定向 ................................................................................................. 845 25.3.6 IIS 重寫規則 .................................................................................................... 846 25.3.7 Apache 重寫規則 ............................................................................................. 848 第 26 章 限流............................................................................................................. 850 26.1 控制併發量 .................................................................................................................. 850 26.1.1 設置併發和等待請求閾值 ............................................................................... 850 26.1.2 初識基於佇列的處理策略 ............................................................................... 853 26.1.3 初識基於棧的處理策略 ................................................................................... 855 26.2 併發限制中介軟體 ........................................................................................................... 856 26.2.1 等待佇列策略 .................................................................................................. 856 26.2.2 ConcurrencyLimiterMiddleware ........................................................................ 856 26.2.3 處理拒絕請求 .................................................................................................. 858 26.3 等待佇列策略 ...........................
蔣金楠 網名Artech, 軟體顧問。微軟6任MVP(Solutions Architecture、Connected System與Microsoft Integration)。中國 .NET 技術領域 專家,著有《WCF全面解析》)、《ASP.NET MVC 5框架揭秘》等多部領域暢銷著作。對.NET Framework、C#、ASP.NET、SQL Server、設計模式、軟體架構,以及主流開源框架有著深入研究,同時對.NET Remoting、MSMQ通信技術有深入的理解。博客園頭牌博主,51CTO 博客,知名技術公眾號“大內老A”號主。
最近浏览商品
客服公告
热门活动
订阅电子报