{"id":134,"date":"2022-08-24T19:25:58","date_gmt":"2022-08-24T11:25:58","guid":{"rendered":"https:\/\/miie.net\/?p=134"},"modified":"2022-08-24T19:25:58","modified_gmt":"2022-08-24T11:25:58","slug":"ultimate-asp-net-core-web-api-table-of-contents","status":"publish","type":"post","link":"https:\/\/diji.net\/?p=134","title":{"rendered":"Ultimate ASP.NET Core Web API Table Of Contents"},"content":{"rendered":"<p>Ultimate ASP.NET Core Web API<\/p>\n<p>TABLE OF CONTENTS ...... 3<br \/>\n\u76ee\u5f55<\/p>\n<p>1 PROJECT CONFIGURATION ...... 11<br \/>\n\u9879\u76ee\u914d\u7f6e<\/p>\n<p>1.1 Creating a New Project...... 11<br \/>\n\u521b\u5efa\u65b0\u9879\u76ee<\/p>\n<p>1.2 launchSettings.json File Configuration ...... 13<br \/>\nlaunchSettings.json \u6587\u4ef6\u914d\u7f6e<\/p>\n<p>1.3 Program.cs and Startup.cs Explanations ...... 14<br \/>\nProgram.cs and Startup.cs \u6587\u4ef6\u89e3\u6790<\/p>\n<p>1.4 Extension Methods and CORS Configuration ...... 16<br \/>\n\u6269\u5c55\u65b9\u6cd5\u548c CORS \u914d\u7f6e<\/p>\n<p>1.5 IIS Configuration ...... 17<br \/>\nIIS \u914d\u7f6e<\/p>\n<p>1.6 Additional Code in the Startup Class ...... 19<br \/>\n\u542f\u52a8\u7c7b\uff08Startup\uff09\u4e2d\u7684\u5176\u4ed6\u4ee3\u7801<\/p>\n<p>1.7 Environment-Based Settings ...... 20<br \/>\n\u73af\u5883\u8bbe\u7f6e<\/p>\n<p>2 CONFIGURING A LOGGING SERVICE ...... 23<br \/>\n\u914d\u7f6e\u65e5\u5fd7\u8bb0\u5f55\u670d\u52a1<\/p>\n<p>2.1 Creating the Required Projects ...... 23<br \/>\n\u521b\u5efa\u6240\u9700\u9879\u76ee<\/p>\n<p>2.2 Creating the ILoggerManager Interface and Installing NLog ...... 24<br \/>\n\u521b\u5efa ILoggerManager \u63a5\u53e3\u5e76\u5b89\u88c5 NLog<\/p>\n<p>2.3 Implementing the Interface and Nlog.Config File ...... 26<br \/>\n\u5b9e\u73b0\u63a5\u53e3\u548c Nlog.Config \u6587\u4ef6<\/p>\n<p>2.4 Configuring Logger Service for Logging Messages ...... 27<br \/>\n\u914d\u7f6e\u8bb0\u5f55\u5668\u670d\u52a1\u4ee5\u8bb0\u5f55\u6d88\u606f<\/p>\n<p>2.5 DI, IoC, and Logger Service Testing ...... 29<br \/>\nDI\u3001IoC \u548c\u8bb0\u5f55\u5668\u670d\u52a1\u6d4b\u8bd5<\/p>\n<p>3 DATABASE MODEL AND REPOSITORY PATTERN ...... 31<br \/>\n\u6570\u636e\u5e93\u6a21\u578b\u548c\u5b58\u50a8\u5e93\u6a21\u5f0f<\/p>\n<p>3.1 Creating Models ...... 31<br \/>\n\u521b\u5efa\u6a21\u578b<\/p>\n<p>3.2 Context Class and the Database Connection ...... 33<br \/>\n\u4e0a\u4e0b\u6587\u7c7b\u548c\u6570\u636e\u5e93\u8fde\u63a5<\/p>\n<p>3.3 Migration and Initial Data Seed ...... 35<br \/>\n\u8fc1\u79fb\u548c\u521d\u59cb\u6570\u636e\u79cd\u5b50<\/p>\n<p>3.4 Repository Pattern Logic ...... 38<br \/>\n\u5b58\u50a8\u5e93\u6a21\u5f0f\u903b\u8f91<\/p>\n<p>3.5 Repository User Interfaces and Classes ...... 40<br \/>\n\u5b58\u50a8\u5e93\u7528\u6237\u754c\u9762\u548c\u7c7b<\/p>\n<p>3.6 Creating a Repository Manager ...... 42<br \/>\n\u521b\u5efa\u5b58\u50a8\u5e93\u7ba1\u7406\u5668<\/p>\n<p>4 HANDLING GET REQUESTS ...... 46<br \/>\n\u5904\u7406\u83b7\u53d6\u8bf7\u6c42<\/p>\n<p>4.1 Controllers and Routing in WEB API ...... 46<br \/>\nWEB API\u4e2d\u7684\u63a7\u5236\u5668\u548c\u8def\u7531<\/p>\n<p>4.2 Naming Our Resources ...... 48<br \/>\n\u547d\u540d\u6211\u4eec\u7684\u8d44\u6e90<\/p>\n<p>4.3 Getting All Companies From the Database ...... 49<br \/>\n\u4ece\u6570\u636e\u5e93\u4e2d\u83b7\u53d6\u6240\u6709\u516c\u53f8\u6570\u636e<\/p>\n<p>4.4 Testing the Result with Postman ...... 52<br \/>\n\u4f7f\u7528Postman\u6d4b\u8bd5\u7ed3\u679c<\/p>\n<p>4.5 DTO Classes vs. Entity Model Classes ...... 54<br \/>\nDTO \u7c7b\u4e0e\u5b9e\u4f53\u6a21\u578b\u7c7b<\/p>\n<p>4.6 Using AutoMapper in ASP.NET Core ...... 57<br \/>\n\u5728 ASP.NET Core\u4e2d\u4f7f\u7528\u81ea\u52a8\u6620\u5c04\u5668<\/p>\n<p>5 GLOBAL ERROR HANDLING ...... 60<br \/>\n\u5168\u5c40\u9519\u8bef\u5904\u7406<\/p>\n<p>5.1 Handling Errors Globally with the Built-In Middleware...... 60<br \/>\n\u4f7f\u7528\u5185\u7f6e\u4e2d\u95f4\u4ef6\u5168\u5c40\u5904\u7406\u9519\u8bef<\/p>\n<p>5.2 Startup Class Modification ...... 61<br \/>\n\u542f\u52a8\uff08Startup\uff09\u7c7b\u4fee\u6539<\/p>\n<p>5.3 Testing the Result ...... 62<br \/>\n\u6d4b\u8bd5\u7ed3\u679c<\/p>\n<p>6 GETTING ADDITIONAL RESOURCES ...... 64<br \/>\n\u83b7\u53d6\u5176\u4ed6\u8d44\u6e90<\/p>\n<p>6.1 Getting a Single Resource From the Database ...... 64<br \/>\n\u4ece\u6570\u636e\u5e93\u4e2d\u83b7\u53d6\u5355\u4e2a\u8d44\u6e90<\/p>\n<p>6.2 Parent\/Child Relationships in Web API ...... 66<br \/>\nWeb API \u4e2d\u7684\u7236\u5b50\u5173\u7cfb<\/p>\n<p>6.3 Getting a Single Employee for Company ...... 69<br \/>\n\u4e3a\u516c\u53f8\u62db\u8058\u4e00\u540d\u5458\u5de5<\/p>\n<p>7 CONTENT NEGOTIATION ...... 72<br \/>\n\u5185\u5bb9\u534f\u5546<\/p>\n<p>7.1 What Do We Get Out of the Box? ...... 72<br \/>\n\u6211\u4eec\u4ece\u76d2\u5b50\u91cc\u5f97\u5230\u4ec0\u4e48\uff1f<\/p>\n<p>7.2 Changing the Default Configuration of Our Project ...... 73<br \/>\n\u66f4\u6539\u9879\u76ee\u7684\u9ed8\u8ba4\u914d\u7f6e<\/p>\n<p>7.3 Testing Content Negotiation ...... 74<br \/>\n\u6d4b\u8bd5\u5185\u5bb9\u534f\u5546<\/p>\n<p>7.4 Restricting Media Types ...... 74<br \/>\n\u9650\u5236\u5a92\u4f53\u7c7b\u578b<\/p>\n<p>7.5 More About Formatters ...... 75<br \/>\n\u66f4\u591a\u683c\u5f0f<\/p>\n<p>7.6 Implementing a Custom Formatter ...... 76<br \/>\n\u5b9e\u73b0\u81ea\u5b9a\u4e49\u683c\u5f0f<\/p>\n<p>8 METHOD SAFETY AND METHOD IDEMPOTENCY ...... 79<br \/>\n\u65b9\u6cd5\u5b89\u5168\u6027\u548c\u65b9\u6cd5\u5e42\u7b49\u6027<\/p>\n<p>9 CREATING RESOURCES ...... 81<br \/>\n\u521b\u5efa\u8d44\u6e90<\/p>\n<p>9.1 Handling POST Requests ...... 81<br \/>\n\u5904\u7406POST\u8bf7\u6c42<\/p>\n<p>9.2 Code Explanation ...... 83<br \/>\n\u4ee3\u7801\u8bf4\u660e<\/p>\n<p>9.3 Creating a Child Resource ...... 85<br \/>\n\u521b\u5efa\u5b50\u8d44\u6e90<\/p>\n<p>9.4 Creating Children Resources Together with a Parent ...... 88<br \/>\n\u4e0e\u7236\u8d44\u6e90\u4e00\u8d77\u521b\u5efa\u5b50\u8d44\u6e90<\/p>\n<p>9.5 Creating a Collection of Resources ...... 90<br \/>\n\u521b\u5efa\u8d44\u6e90\u96c6\u5408<\/p>\n<p>9.6 Model Binding in API ...... 93<br \/>\nAPI\u4e2d\u7684\u6a21\u578b\u7ed1\u5b9a<\/p>\n<p>10 WORKING WITH DELETE REQUESTS ...... 97<br \/>\n\u4f7f\u7528DELETE\u8bf7\u6c42<\/p>\n<p>10.1 Deleting a Parent Resource with its Children ...... 98<br \/>\n\u5220\u9664\u7236\u8d44\u6e90\u53ca\u5176\u5b50\u8d44\u6e90<\/p>\n<p>11 WORKING WITH PUT REQUESTS ...... 101<br \/>\n\u4f7f\u7528 PUT \u8bf7\u6c42<\/p>\n<p>11.1 Updating Employee ...... 101<br \/>\n\u66f4\u65b0\u5458\u5de5<\/p>\n<p>11.1.1 About the Update Method from the RepositoryBase Class ......104<br \/>\n\u5173\u4e8e\u5b58\u50a8\u5e93\u5e93\u7c7b\u4e2d\u7684\u66f4\u65b0\u65b9\u6cd5<\/p>\n<p>11.2 Inserting Resources while Updating One ...... 105<br \/>\n\u5728\u66f4\u65b0\u65f6\u63d2\u5165\u8d44\u6e90<\/p>\n<p>12 WORKING WITH PATCH REQUESTS ...... 107<br \/>\n\u5904\u7406PATCH\u8bf7\u6c42<\/p>\n<p>12.1 Applying PATCH to the Employee Entity ...... 108<br \/>\n\u5c06 PATCH \u5e94\u7528\u4e8e\u5458\u5de5\u5b9e\u4f53<\/p>\n<p>13 VALIDATION ...... 114<br \/>\n\u9a8c\u8bc1<\/p>\n<p>13.1 Validation while Creating Resource ...... 115<br \/>\n\u521b\u5efa\u8d44\u6e90\u65f6\u7684\u9a8c\u8bc1<\/p>\n<p>13.1.1 Validating Int Type ......119<br \/>\n\u9a8c\u8bc1Int\u7c7b\u578b<\/p>\n<p>13.2 Validation for PUT Requests ...... 121<br \/>\nPUT\u8bf7\u6c42\u7684\u9a8c\u8bc1<\/p>\n<p>13.3 Validation for PATCH Requests ...... 123<br \/>\n\u8865\u4e01\u8bf7\u6c42\u7684\u9a8c\u8bc1<\/p>\n<p>14 ASYNCHRONOUS CODE ...... 127<br \/>\n\u5f02\u6b65\u4ee3\u7801<\/p>\n<p>14.1 What is Asynchronous Programming? ...... 127<br \/>\n\u4ec0\u4e48\u662f\u5f02\u6b65\u7f16\u7a0b<\/p>\n<p>14.2 Async, Await Keywords, and Return Types ...... 128<br \/>\nAsync, Await\u5173\u952e\u5b57\u548c\u8fd4\u56de\u7c7b\u578b<\/p>\n<p>14.2.1 The IRepositoryBase Interface and the RepositoryBase Class Explanation ...... 130<br \/>\nIRepositoryBase\u63a5\u53e3\u548cRepositoryBase\u7c7b\u8bf4\u660e<\/p>\n<p>14.3 Modifying the ICompanyRepository Interface and the CompanyRepository Class ...... 130<br \/>\n\u4fee\u6539ICompanyRepository\u63a5\u53e3\u548cCompanyRepositoryClass<\/p>\n<p>14.4 IRepositoryManager and RepositoryManager Changes...... 131<br \/>\nIRepositoryManager \u548c RepositoryManager\u53d8\u66f4<\/p>\n<p>14.5 Controller Modification ...... 132<br \/>\n\u63a7\u5236\u5668\u4fee\u6539<\/p>\n<p>15 ACTION FILTERS ...... 136<br \/>\n\u52a8\u4f5c\u8fc7\u6ee4\u5668<\/p>\n<p>15.1 Action Filters Implementation ...... 136<br \/>\n\u884c\u52a8\u8fc7\u6ee4\u5668\u7684\u5b9e\u65bd<\/p>\n<p>15.2 The Scope of Action Filters ...... 137<br \/>\n\u884c\u52a8\u8303\u56f4<\/p>\n<p>15.3 Order of Invocation ...... 138<br \/>\n\u8c03\u7528\u987a\u5e8f<\/p>\n<p>15.4 Improving the Code with Action Filters ...... 140<br \/>\n\u4f7f\u7528\u52a8\u4f5c\u8fc7\u6ee4\u5668\u6539\u8fdb\u4ee3\u7801<\/p>\n<p>15.5 Validation with Action Filters ...... 140<br \/>\n\u4f7f\u7528\u52a8\u4f5c\u8fc7\u6ee4\u5668\u8fdb\u884c\u9a8c\u8bc1<\/p>\n<p>15.6 Dependency Injection in Action Filters ...... 144<br \/>\n\u4f9d\u8d56\u6ce8\u5165\u5728\u7528\u8fc7\u6ee4\u5668<\/p>\n<p>16 PAGING ...... 150<br \/>\n\u5206\u9875<\/p>\n<p>16.1 What is Paging? ...... 150<br \/>\n\u4ec0\u4e48\u662f\u5206\u9875<\/p>\n<p>16.2 Paging Implementation ...... 151<br \/>\n\u5206\u9875\u5b9e\u73b0<\/p>\n<p>16.3 Concrete Query ...... 153<br \/>\n\u5177\u4f53\u67e5\u8be2<\/p>\n<p>16.4 Improving the Solution ...... 156<br \/>\n\u6539\u8fdb\u89e3\u51b3\u65b9\u6848<\/p>\n<p>16.4.1 Additional Advice ......159<br \/>\n\u5176\u4ed6\u5efa\u8bae<\/p>\n<p>17 FILTERING ...... 160<br \/>\n\u7b5b\u9009\uff08\u8fc7\u6ee4\uff09<\/p>\n<p>17.1 What is Filtering? ...... 160<br \/>\n\u4ec0\u4e48\u662f\u7b5b\u9009<\/p>\n<p>17.2 How is Filtering Different from Searching? ...... 161<br \/>\n\u7b5b\u9009\u4e0e\u641c\u7d22\u6709\u4f55\u4e0d\u540c<\/p>\n<p>17.3 How to Implement Filtering in ASP.NET Core Web API ...... 162<br \/>\n\u5982\u4f55\u5728 ASP.NET \u6838\u5fc3 Web API \u4e2d\u5b9e\u73b0\u7b5b\u9009<\/p>\n<p>17.4 Sending and Testing a Query ...... 164<br \/>\n\u53d1\u9001\u548c\u6d4b\u8bd5\u67e5\u8be2<\/p>\n<p>18 SEARCHING ...... 167<br \/>\n\u641c\u7d22<\/p>\n<p>18.1 What is Searching?...... 167<br \/>\n\u4ec0\u4e48\u662f\u641c\u7d22<\/p>\n<p>18.2 Implementing Searching in Our Application ...... 167<br \/>\n\u5728\u6211\u4eec\u7684\u5e94\u7528\u7a0b\u5e8f\u4e2d\u5b9e\u73b0\u641c\u7d22<\/p>\n<p>18.3 Testing Our Implementation ...... 169<br \/>\n\u6d4b\u8bd5\u6211\u4eec\u7684\u5b9e\u73b0<\/p>\n<p>19 SORTING ...... 172<br \/>\n\u6392\u5e8f<\/p>\n<p>19.1 What is Sorting? ...... 172<br \/>\n\u4ec0\u4e48\u662f\u6392\u5e8f<\/p>\n<p>19.2 How to Implement Sorting in ASP.NET Core Web API ...... 174<br \/>\n\u5982\u4f55\u5728 ASP.NET \u6838\u5fc3 Web API\u4e2d\u5b9e\u73b0\u6392\u5e8f<\/p>\n<p>19.3 Implementation \u2013 Step by Step ...... 176<br \/>\n\u5b9e\u65bd \u2013 \u9010\u6b65\u6267\u884c <\/p>\n<p>19.4 Testing Our Implementation ...... 178<br \/>\n\u6d4b\u8bd5\u6211\u4eec\u7684\u5b9e\u73b0<\/p>\n<p>19.5 Improving the Sorting Functionality...... 179<br \/>\n\u6539\u8fdb\u6392\u5e8f\u529f\u80fd<\/p>\n<p>20 DATA SHAPING ...... 182<br \/>\n\u6570\u636e\u6574\u5f62<\/p>\n<p>20.1 What is Data Shaping? ...... 182<br \/>\n\u4ec0\u4e48\u662f\u6570\u636e\u6574\u5f62<\/p>\n<p>20.2 How to Implement Data Shaping ...... 183<br \/>\n\u5982\u4f55\u5b9e\u73b0\u6570\u636e\u6574\u5f62<\/p>\n<p>20.3 Step-by-Step Implementation ...... 185<br \/>\n\u5206\u6b65\u5b9e\u65bd<\/p>\n<p>20.4 Resolving XML Serialization Problems ...... 189<br \/>\n\u89e3\u51b3 XML \u5e8f\u5217\u5316\u95ee\u9898<\/p>\n<p>21 SUPPORTING HATEOAS ...... 192<br \/>\n\u652f\u6301HATEOAS<\/p>\n<p>21.1 What is HATEOAS and Why is it so Important?...... 192<br \/>\n\u4ec0\u4e48\u662fHATEOAS\uff0c\u4e3a\u4ec0\u4e48\u5b83\u5982\u6b64\u91cd\u8981\uff1f<\/p>\n<p>21.1.1 Typical Response with HATEOAS Implemented ......193<br \/>\n\u5bf9 HATEOAS \u5b9e\u65bd\u7684\u5178\u578b\u54cd\u5e94<\/p>\n<p>21.1.2 What is a Link? ......193<br \/>\n\u4ec0\u4e48\u662f\u94fe\u63a5<\/p>\n<p>21.1.3 Pros\/Cons of Implementing HATEOAS ......194<br \/>\n\u5b9e\u65bd HATEOAS \u7684\u5229\u5f0a<\/p>\n<p>21.2 Adding Links in the Project ...... 194<br \/>\n\u5728\u9879\u76ee\u4e2d\u6dfb\u52a0\u94fe\u63a5<\/p>\n<p>21.3 Additional Project Changes ...... 197<br \/>\n\u5176\u4ed6\u9879\u76ee\u53d8\u66f4<\/p>\n<p>21.4 Adding Custom Media Types ...... 198<br \/>\n\u6dfb\u52a0\u81ea\u5b9a\u4e49\u5a92\u4f53\u7c7b\u578b<\/p>\n<p>21.4.1 Registering Custom Media Types ......199<br \/>\n\u6ce8\u518c\u81ea\u5b9a\u4e49\u5a92\u4f53\u7c7b\u578b<\/p>\n<p>21.4.2 Implementing a Media Type Validation Filter ......200<br \/>\n\u5b9e\u73b0\u5a92\u4f53\u7c7b\u578b\u9a8c\u8bc1\u7b5b\u9009\u5668<\/p>\n<p>21.5 Implementing HATEOAS ...... 201<br \/>\n\u5b9e\u65bd HATEOAS<\/p>\n<p>22 WORKING WITH OPTIONS AND HEAD REQUESTS ...... 207<br \/>\n\u4f7f\u7528\u9009\u9879\u548c HEAD \u8bf7\u6c42<\/p>\n<p>22.1 OPTIONS HTTP Request ...... 207<br \/>\n\u9009\u9879 HTTP \u8bf7\u6c42<\/p>\n<p>22.2 OPTIONS Implementation ...... 207<br \/>\n\u6267\u884c\u60c5\u51b5<\/p>\n<p>22.3 Head HTTP Request ...... 209<br \/>\n\u5934 HTTP \u8bf7\u6c42<\/p>\n<p>22.4 HEAD Implementation ...... 209<br \/>\n\u6267\u884c<\/p>\n<p>23 ROOT DOCUMENT ...... 211<br \/>\n\u6839\u6587\u6863<\/p>\n<p>23.1 Root Document Implementation ...... 211<br \/>\n\u6839\u6587\u6863\u5b9e\u73b0<\/p>\n<p>24 VERSIONING APIS ...... 216<br \/>\n\u7248\u672c\u63a7\u5236<\/p>\n<p>24.1 Required Package Installation and Configuration...... 216<br \/>\n\u6240\u9700\u7684\u8f6f\u4ef6\u5305\u5b89\u88c5\u548c\u914d\u7f6e<\/p>\n<p>24.2 Versioning Examples ...... 218<br \/>\n\u7248\u672c\u63a7\u5236\u793a\u4f8b<\/p>\n<p>24.2.1 Using Query String ......219<br \/>\n\u4f7f\u7528\u67e5\u8be2\u5b57\u7b26\u4e32<\/p>\n<p>24.2.2 Using URL Versioning ......220<br \/>\n\u4f7f\u7528 URL \u7248\u672c\u63a7\u5236<\/p>\n<p>24.2.3 HTTP Header Versioning ......221<br \/>\nHTTP \u6807\u5934\u7248\u672c\u63a7\u5236<\/p>\n<p>24.2.4 Deprecating Versions ......222<br \/>\n\u5f03\u7528\u7248\u672c<\/p>\n<p>24.2.5 Using Conventions ......223<br \/>\n\u4f7f\u7528\u7ea6\u5b9a<\/p>\n<p>25 CACHING ...... 224<br \/>\n\u7f13\u5b58<\/p>\n<p>25.1 About Caching ...... 224<br \/>\n\u5173\u4e8e\u7f13\u5b58 <\/p>\n<p>25.1.1 Cache Types ......224<br \/>\n\u7f13\u5b58\u7c7b\u578b<\/p>\n<p>25.1.2 Response Cache Attribute ......225<br \/>\n\u54cd\u5e94\u7f13\u5b58\u5c5e\u6027<\/p>\n<p>25.2 Adding Cache Headers...... 225<br \/>\n\u6dfb\u52a0\u7f13\u5b58\u6807\u5934<\/p>\n<p>25.3 Adding Cache-Store ...... 227<br \/>\n\u6dfb\u52a0\u7f13\u5b58\u5b58\u50a8 <\/p>\n<p>25.4 Expiration Model ...... 229<br \/>\n\u8fc7\u671f\u578b\u53f7<\/p>\n<p>25.5 Validation Model...... 231<br \/>\n\u9a8c\u8bc1\u6a21\u578b<\/p>\n<p>25.6 Supporting Validation...... 233<br \/>\n\u652f\u6301\u9a8c\u8bc1<\/p>\n<p>25.6.1 Configuration ......234<br \/>\n\u914d\u7f6e<\/p>\n<p>25.7 Using ETag and Validation ...... 236<br \/>\n\u4f7f\u7528 ETag \u548c\u9a8c\u8bc1<\/p>\n<p>26 RATE LIMITING AND THROTTLING ...... 240<br \/>\n\u901f\u7387\u9650\u5236\u548c\u8282\u6d41<\/p>\n<p>26.1 Implementing Rate Limiting ...... 240<br \/>\n\u5b9e\u65bd\u901f\u7387\u9650\u5236 <\/p>\n<p>27 JWT AND IDENTITY ...... 244<br \/>\nJWT\u548c\u8eab\u4efd\u9a8c\u8bc1<\/p>\n<p>27.1 Implementing Identity in ASP.NET Core Project...... 244<br \/>\n\u5728\u9879\u76ee\u4e2d\u5b9e\u73b0 ASP.NET Core\u8eab\u4efd\u9a8c\u8bc1<\/p>\n<p>27.2 Creating Tables and Inserting Roles ...... 246<br \/>\n\u521b\u5efa\u8868\u548c\u63d2\u5165\u89d2\u8272<\/p>\n<p>27.3 User Creation ...... 248<br \/>\n\u7528\u6237\u521b\u5efa<\/p>\n<p>27.4 Big Picture ...... 251<br \/>\n\u5168\u5c40<\/p>\n<p>27.5 About JWT ...... 252<br \/>\n\u5173\u4e8eJWT<\/p>\n<p>27.6 JWT Configuration ...... 254<br \/>\nJWT\u914d\u7f6e<\/p>\n<p>27.7 Protecting Endpoints ...... 256<br \/>\n\u4fdd\u62a4Endpoints<\/p>\n<p>27.8 Implementing Authentication ...... 257<br \/>\n\u5b9e\u73b0\u8eab\u4efd\u9a8c\u8bc1<\/p>\n<p>27.9 Role-Based Authorization ...... 263<br \/>\n\u57fa\u4e8e\u89d2\u8272\u7684\u6388\u6743<\/p>\n<p>28 DOCUMENTING API WITH SWAGGER ...... 266<br \/>\n\u4f7f\u7528 SWAGGER \u6587\u6863API<\/p>\n<p>28.1 About Swagger ...... 266<br \/>\n\u5173\u4e8eSwagger<\/p>\n<p>28.2 Swagger Integration Into Our Project ...... 267<br \/>\n\u5c06Swagger\u6574\u5408\u8fdb\u9879\u76ee<\/p>\n<p>28.3 Adding Authorization Support ...... 271<br \/>\n\u6dfb\u52a0\u6388\u6743\u652f\u6301<\/p>\n<p>28.4 Extending Swagger Configuration ...... 274<br \/>\n\u6269\u5c55 Swagger \u914d\u7f6e<\/p>\n<p>29 DEPLOYMENT TO IIS ...... 278<br \/>\n\u90e8\u7f72\u5230 IIS<\/p>\n<p>29.1 Creating Publish Files ...... 278<br \/>\n\u521b\u5efa\u53d1\u5e03\u6587\u4ef6<\/p>\n<p>29.2 Windows Server Hosting Bundle ...... 280<br \/>\nWindows Server Hosting Bundle<\/p>\n<p>29.3 Installing IIS...... 280<br \/>\n\u5b89\u88c5 IIS<\/p>\n<p>29.4 Configuring Environment File ...... 283<br \/>\n\u914d\u7f6e\u73af\u5883\u6587\u4ef6<\/p>\n<p>29.5 Testing Deployed Application ...... 285<br \/>\n\u6d4b\u8bd5\u5df2\u90e8\u7f72\u7684\u5e94\u7528\u7a0b\u5e8f<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ultimate ASP.NET Core Web API TABLE OF CONTENTS &#8230;&#8230; 3 \u76ee\u5f55 1 PROJECT CONFIGURATION &#8230;&#8230; 11 \u9879\u76ee\u914d\u7f6e 1.1 Creating a New Project&#8230;&#8230; 11 \u521b\u5efa\u65b0\u9879\u76ee 1.2 launchSettings.json File Configuration &#8230;&#8230; 13 launchSettings.json \u6587\u4ef6\u914d\u7f6e 1.3 Program.cs and Startup.cs Explanations &#8230;&#8230; 14 Program.cs and Startup.cs \u6587\u4ef6\u89e3\u6790 1.4 Extension Methods and CORS Configuration &#8230;&#8230; 16 \u6269\u5c55\u65b9\u6cd5\u548c CORS \u914d\u7f6e 1.5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[23],"class_list":["post-134","post","type-post","status-publish","format-standard","hentry","category-csharp","tag-ultimate-asp-net-core-web-api"],"_links":{"self":[{"href":"https:\/\/diji.net\/index.php?rest_route=\/wp\/v2\/posts\/134","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/diji.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/diji.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/diji.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/diji.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=134"}],"version-history":[{"count":0,"href":"https:\/\/diji.net\/index.php?rest_route=\/wp\/v2\/posts\/134\/revisions"}],"wp:attachment":[{"href":"https:\/\/diji.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/diji.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/diji.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}