{"id":570,"date":"2025-04-05T03:17:55","date_gmt":"2025-04-04T19:17:55","guid":{"rendered":"https:\/\/www.hyy.net\/?p=570"},"modified":"2025-04-05T03:17:55","modified_gmt":"2025-04-04T19:17:55","slug":"asp-net-core-in-action-2-understanding-asp-net-core","status":"publish","type":"post","link":"https:\/\/diji.net\/?p=570","title":{"rendered":"ASP.NET Core in Action 2 Understanding ASP.NET Core"},"content":{"rendered":"<h1>Part 1 Getting started with minimal APIs<\/h1>\n<h1>\u7b2c 1 \u90e8\u5206\uff1a\u5f00\u59cb\u4f7f\u7528\u6700\u5c11\u7684 API<\/h1>\n<p>Web applications are everywhere these days, from social media web apps and news sites to the apps on your phone. Behind the scenes, there's almost always a server running a web application or an HTTP API. Web applications are expected to be infinitely scalable, deployed to the cloud, and highly performant. Getting started can be overwhelming at the best of times, and doing so with such high expectations can be even more of a challenge.<\/p>\n<p>\u5982\u4eca\uff0cWeb \u5e94\u7528\u7a0b\u5e8f\u65e0\u5904\u4e0d\u5728\uff0c\u4ece\u793e\u4ea4\u5a92\u4f53 Web \u5e94\u7528\u7a0b\u5e8f\u548c\u65b0\u95fb\u7f51\u7ad9\u5230\u624b\u673a\u4e0a\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u5728\u5e55\u540e\uff0c\u51e0\u4e4e\u603b\u662f\u6709\u670d\u52a1\u5668\u8fd0\u884c Web \u5e94\u7528\u7a0b\u5e8f\u6216 HTTP API\u3002Web \u5e94\u7528\u7a0b\u5e8f\u5e94\u5177\u6709\u65e0\u9650\u53ef\u6269\u5c55\u6027\u3001\u90e8\u7f72\u5230\u4e91\u4e2d\u548c\u9ad8\u6027\u80fd\u3002\u5728\u6700\u597d\u7684\u60c5\u51b5\u4e0b\uff0c\u5f00\u59cb\u53ef\u80fd\u4f1a\u8ba9\u4eba\u4e0d\u77e5\u6240\u63aa\uff0c\u800c\u5e26\u7740\u5982\u6b64\u9ad8\u7684\u671f\u671b\u8fd9\u6837\u505a\u53ef\u80fd\u662f\u4e00\u4e2a\u66f4\u5927\u7684\u6311\u6218\u3002<\/p>\n<p>The good news for you as a reader is that ASP.NET Core was designed to meet those requirements. Whether you need a simple website, a complex e-commerce web app, or a distributed web of microservices, you can use your knowledge of ASP.NET Core to build lean web apps that fit your needs. ASP.NET Core lets you build and run web apps in Windows, Linux, or macOS. It's highly modular, so you use only the components you need, keeping your app as compact and performant as possible.<\/p>\n<p>\u5bf9\u4e8e\u8bfb\u8005\u6765\u8bf4\uff0c\u597d\u6d88\u606f\u662f ASP.NET Core \u65e8\u5728\u6ee1\u8db3\u8fd9\u4e9b\u8981\u6c42\u3002\u65e0\u8bba\u60a8\u9700\u8981\u7b80\u5355\u7684\u7f51\u7ad9\u3001\u590d\u6742\u7684\u7535\u5b50\u5546\u52a1 Web \u5e94\u7528\u7a0b\u5e8f\u8fd8\u662f\u5fae\u670d\u52a1\u7684\u5206\u5e03\u5f0f Web\uff0c\u60a8\u90fd\u53ef\u4ee5\u5229\u7528\u81ea\u5df1\u7684 ASP.NET Core \u77e5\u8bc6\u6765\u6784\u5efa\u7b26\u5408\u60a8\u9700\u6c42\u7684\u7cbe\u76ca Web \u5e94\u7528\u7a0b\u5e8f\u3002ASP.NET Core \u5141\u8bb8\u60a8\u5728 Windows\u3001Linux \u6216 macOS \u4e2d\u6784\u5efa\u548c\u8fd0\u884c Web \u5e94\u7528\u7a0b\u5e8f\u3002\u5b83\u662f\u9ad8\u5ea6\u6a21\u5757\u5316\u7684\uff0c\u56e0\u6b64\u60a8\u53ea\u9700\u4f7f\u7528\u6240\u9700\u7684\u7ec4\u4ef6\uff0c\u4ece\u800c\u4f7f\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u5c3d\u53ef\u80fd\u7d27\u51d1\u548c\u9ad8\u6027\u80fd\u3002<\/p>\n<p>In part 1 you'll go from a standing start all the way to building your first API applications. Chapter 2 gives you a high-level overview of ASP.NET Core, which you'll find especially useful if you're new to web development in general. You'll get your first glimpse of a full ASP.NET Core application in chapter 3; we'll look at each component of the app in turn and see how they work together to generate a response.<\/p>\n<p>\u5728\u7b2c 1 \u90e8\u5206\u4e2d\uff0c\u60a8\u5c06\u4ece\u96f6\u5f00\u59cb\u4e00\u76f4\u5230\u6784\u5efa\u60a8\u7684\u7b2c\u4e00\u4e2a API \u5e94\u7528\u7a0b\u5e8f\u3002\u7b2c 2 \u7ae0\u4e3a\u60a8\u63d0\u4f9b\u4e86 ASP.NET Core \u7684\u9ad8\u7ea7\u6982\u8ff0\uff0c\u5982\u679c\u60a8\u4e00\u822c\u662f Web \u5f00\u53d1\u7684\u65b0\u624b\uff0c\u60a8\u4f1a\u53d1\u73b0\u5b83\u7279\u522b\u6709\u7528\u3002\u5728\u7b2c 3 \u7ae0\u4e2d\uff0c\u60a8\u5c06\u9996\u6b21\u4e86\u89e3\u5b8c\u6574\u7684 ASP.NET Core \u5e94\u7528\u7a0b\u5e8f;\u6211\u4eec\u5c06\u770b\u770bapp \u4e2d\uff0c\u5e76\u67e5\u770b\u5b83\u4eec\u5982\u4f55\u534f\u540c\u5de5\u4f5c\u4ee5\u751f\u6210\u54cd\u5e94\u3002<\/p>\n<p>Chapter 4 looks in detail at the middleware pipeline, which defines how incoming web requests are processed and how a response is generated. We'll look at several standard pieces of middleware and see how they can be combined to create your application's pipeline.<\/p>\n<p>\u7b2c 4 \u7ae0\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u4e2d\u95f4\u4ef6\u7ba1\u9053\uff0c\u5b83\u5b9a\u4e49\u4e86\u5982\u4f55\u5904\u7406\u4f20\u5165\u7684 Web \u8bf7\u6c42\u4ee5\u53ca\u5982\u4f55\u751f\u6210\u54cd\u5e94\u3002\u6211\u4eec\u5c06\u4ecb\u7ecd\u51e0\u4e2a\u6807\u51c6\u7684\u4e2d\u95f4\u4ef6\uff0c\u5e76\u4e86\u89e3\u5982\u4f55\u5c06\u5b83\u4eec\u7ec4\u5408\u8d77\u6765\u521b\u5efa\u5e94\u7528\u7a0b\u5e8f\u7684\u7ba1\u9053\u3002<\/p>\n<p>Chapters 5 through 7 focus on building ASP.NET Core apps with minimal API endpoints, which are the new simplified approach to building JSON APIs in ASP.NET Core apps. In chapter 5 you'll learn how to create endpoints that generate JSON, how to use filters to extract common behavior, and how to use route groups to organize your APIs. In chapter 6 you'll learn about routing, the process of mapping URLs to endpoints. And in chapter 7 you'll learn about model binding and validation.<\/p>\n<p>\u7b2c 5 \u7ae0\u5230\u7b2c 7 \u7ae0\u91cd\u70b9\u4ecb\u7ecd\u5982\u4f55\u6784\u5efa\u5177\u6709\u6700\u5c11 API \u7aef\u70b9\u7684 ASP.NET Core \u5e94\u7528\u7a0b\u5e8f\uff0c\u8fd9\u662f\u5728 ASP.NET Core \u5e94\u7528\u7a0b\u5e8f\u4e2d\u6784\u5efa JSON API \u7684\u65b0\u7b80\u5316\u65b9\u6cd5\u3002\u5728\u7b2c 5 \u7ae0\u4e2d\uff0c\u60a8\u5c06\u5b66\u4e60\u5982\u4f55\u521b\u5efa\u751f\u6210 JSON \u7684\u7ec8\u7aef\u8282\u70b9\uff0c\u5982\u4f55\u4f7f\u7528\u8fc7\u6ee4\u5668\u63d0\u53d6\u5e38\u89c1\u884c\u4e3a\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u8def\u7531\u7ec4\u6765\u7ec4\u7ec7 API\u3002\u5728\u7b2c 6 \u7ae0\u4e2d\uff0c\u60a8\u5c06\u4e86\u89e3\u8def\u7531\uff0c\u5373\u5c06 URL \u6620\u5c04\u5230\u7aef\u70b9\u7684\u8fc7\u7a0b\u3002\u5728\u7b2c 7 \u7ae0\u4e2d\uff0c\u60a8\u5c06\u5b66\u4e60\u6a21\u578b\u7ed1\u5b9a\u548c\u9a8c\u8bc1\u3002<\/p>\n<p>There's a lot of content in part 1, but by the end you'll be well on your way to building simple APIs with ASP.NET Core. Inevitably, I'll gloss over some of the more complex configuration aspects of the framework, but you should get a good understanding of minimal APIs and how you can use them to build simple APIs. In later parts of this book, you'll learn how to configure your application and add extra features, such as user profiles and database interaction.<\/p>\n<p>\u7b2c 1 \u90e8\u5206\u5185\u5bb9\u4e30\u5bcc\uff0c\u4f46\u5230\u6700\u540e\uff0c\u60a8\u5c06\u987a\u5229\u4f7f\u7528 ASP.NET Core \u6784\u5efa\u7b80\u5355\u7684 API\u3002\u4e0d\u53ef\u907f\u514d\u5730\uff0c\u6211\u5c06\u7565\u8fc7\u6846\u67b6\u7684\u4e00\u4e9b\u66f4\u590d\u6742\u7684\u914d\u7f6e\u65b9\u9762\uff0c\u4f46\u60a8\u5e94\u8be5\u5f88\u597d\u5730\u4e86\u89e3\u6700\u5c0f\u7684 API \u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u5b83\u4eec\u6765\u6784\u5efa\u7b80\u5355\u7684 API\u3002\u5728\u672c\u4e66\u7684\u540e\u9762\u90e8\u5206\uff0c\u60a8\u5c06\u5b66\u4e60\u5982\u4f55\u914d\u7f6e\u5e94\u7528\u7a0b\u5e8f\u5e76\u6dfb\u52a0\u989d\u5916\u7684\u529f\u80fd\uff0c\u4f8b\u5982\u7528\u6237\u914d\u7f6e\u6587\u4ef6\u548c\u6570\u636e\u5e93\u4ea4\u4e92\u3002<\/p>\n<p>We'll also look at how to build other types of applications, such as server-rendered web apps with Razor Pages.<\/p>\n<p>\u6211\u4eec\u8fd8\u5c06\u4e86\u89e3\u5982\u4f55\u6784\u5efa\u5176\u4ed6\u7c7b\u578b\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u4f8b\u5982\u4f7f\u7528 Razor Pages \u6784\u5efa\u670d\u52a1\u5668\u6e32\u67d3\u7684 Web \u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<h2>2 Understanding ASP.NET Core<\/h2>\n<h2>2 \u4e86\u89e3 ASP.NET Core<\/h2>\n<h3>This chapter covers<\/h3>\n<h3>\u672c\u7ae0\u6db5\u76d6<\/h3>\n<ul>\n<li>\n<p>Why ASP.NET Core was created<br \/>\n\u521b\u5efa ASP.NET Core \u7684\u539f\u56e0<\/p>\n<\/li>\n<li>\n<p>The many application paradigms of ASP.NET Core Approaches to migrating an existing application to ASP.NET Core<br \/>\nASP.NET Core \u7684\u8bb8\u591a\u5e94\u7528\u7a0b\u5e8f\u8303\u4f8b\u5c06\u73b0\u6709\u5e94\u7528\u7a0b\u5e8f\u8fc1\u79fb\u5230 ASP.NET Core \u7684\u65b9\u6cd5<\/p>\n<\/li>\n<\/ul>\n<p>In this chapter, I provide some background on ASP.NET Core: why web frameworks are useful, why ASP.NET Core was created, and how to choose when to use ASP.NET Core. If you\u2019re new to .NET development, this chapter will help you understand the .NET landscape. If you\u2019re already a .NET developer, I provide guidance on whether now is the right time to consider moving your focus to .NET Core and .NET 7, as well as on the advantages ASP.NET Core can o\ufb00er over previous versions of ASP.NET.<\/p>\n<p>\u5728\u672c\u7ae0\u4e2d\uff0c\u6211\u5c06\u63d0\u4f9b\u6709\u5173 ASP.NET Core \u7684\u4e00\u4e9b\u80cc\u666f\u77e5\u8bc6\uff1a\u4e3a\u4ec0\u4e48 Web \u6846\u67b6\u5f88\u6709\u7528\uff0c\u4e3a\u4ec0\u4e48\u521b\u5efa ASP.NET Core\uff0c\u4ee5\u53ca\u5982\u4f55\u9009\u62e9\u4f55\u65f6\u4f7f\u7528 ASP.NET Core\u3002\u5982\u679c\u60a8\u4e0d\u719f\u6089 .NET \u5f00\u53d1\uff0c\u672c\u7ae0\u5c06\u5e2e\u52a9\u60a8\u4e86\u89e3 .NET \u7684\u524d\u666f\u3002\u5982\u679c\u60a8\u5df2\u7ecf\u662f .NET \u5f00\u53d1\u4eba\u5458\uff0c\u6211\u5c06\u63d0\u4f9b\u6307\u5bfc\uff0c\u8bf4\u660e\u73b0\u5728\u662f\u5426\u662f\u8003\u8651\u5c06\u91cd\u70b9\u8f6c\u79fb\u5230 .NET Core \u548c .NET 7 \u7684\u5408\u9002\u65f6\u673a\uff0c\u4ee5\u53ca ASP.NET Core \u76f8\u5bf9\u4e8e\u4ee5\u524d\u7248\u672c\u7684 ASP.NET \u53ef\u4ee5\u63d0\u4f9b\u7684\u4f18\u52bf\u3002<\/p>\n<h3>2.1 Using a web framework\u200c<\/h3>\n<h3>2.1 \u4f7f\u7528 Web \u6846\u67b6<\/h3>\n<p>If you\u2019re new to web development, it can be daunting to move into an area with so many buzzwords and a plethora of ever-changing products. You may be wondering whether all those products are necessary. How hard can it be to return a \ufb01le from a server?<\/p>\n<p>\u5982\u679c\u60a8\u662f Web \u5f00\u53d1\u7684\u65b0\u624b\uff0c\u90a3\u4e48\u8fdb\u5165\u4e00\u4e2a\u62e5\u6709\u5982\u6b64\u591a\u6d41\u884c\u8bed\u548c\u5927\u91cf\u4e0d\u65ad\u53d8\u5316\u7684\u4ea7\u54c1\u7684\u9886\u57df\u53ef\u80fd\u4f1a\u4ee4\u4eba\u751f\u754f\u3002\u60a8\u53ef\u80fd\u60f3\u77e5\u9053\u6240\u6709\u8fd9\u4e9b\u4ea7\u54c1\u662f\u5426\u90fd\u662f\u5fc5\u8981\u7684\u3002\u4ece\u670d\u52a1\u5668\u8fd4\u56de\u6587\u4ef6\u6709\u591a\u96be\uff1f<\/p>\n<p>Well, it\u2019s perfectly possible to build a static web application without the use of a web framework, but its capabilities will be limited. As soon as you want to provide any kind of security or dynamism, you\u2019ll likely run into di\ufb03culties, and the original simplicity that enticed you will fade before your eyes.<\/p>\n<p>\u55ef\uff0c\u5b8c\u5168\u53ef\u4ee5\u5728\u4e0d\u4f7f\u7528 Web \u6846\u67b6\u7684\u60c5\u51b5\u4e0b\u6784\u5efa\u9759\u6001 Web \u5e94\u7528\u7a0b\u5e8f\uff0c\u4f46\u5b83\u7684\u529f\u80fd\u5c06\u53d7\u5230\u9650\u5236\u3002\u4e00\u65e6\u4f60\u60f3\u63d0\u4f9b\u4efb\u4f55\u7c7b\u578b\u7684\u5b89\u5168\u6216\u6d3b\u529b\uff0c\u4f60\u53ef\u80fd\u4f1a\u9047\u5230\u56f0\u96be\uff0c\u6700\u521d\u5438\u5f15\u4f60\u7684\u7b80\u5355\u6027\u4f1a\u5728\u4f60\u773c\u524d\u6d88\u5931\u3002<\/p>\n<p>Just as desktop or mobile development frameworks can help you build native applications, ASP.NET Core makes writing web applications faster, easier, and more secure than trying to build everything from scratch. It contains libraries for common things like<\/p>\n<p>\u6b63\u5982\u684c\u9762\u6216\u79fb\u52a8\u5f00\u53d1\u6846\u67b6\u53ef\u4ee5\u5e2e\u52a9\u60a8\u6784\u5efa\u539f\u751f\u5e94\u7528\u7a0b\u5e8f\u4e00\u6837\uff0cASP.NET Core \u4f7f\u7f16\u5199 Web \u5e94\u7528\u7a0b\u5e8f\u6bd4\u5c1d\u8bd5\u4ece\u5934\u5f00\u59cb\u6784\u5efa\u6240\u6709\u5185\u5bb9\u66f4\u5feb\u3001\u66f4\u8f7b\u677e\u3001\u66f4\u5b89\u5168\u3002\u5b83\u5305\u542b\u7528\u4e8e\u5e38\u89c1\u5185\u5bb9\u7684\u5e93\uff0c\u4f8b\u5982<\/p>\n<ul>\n<li>\n<p>Creating dynamically changing web pages Letting users log in to your web app<br \/>\n\u521b\u5efa\u52a8\u6001\u53d8\u5316\u7684\u7f51\u9875 \u5141\u8bb8\u7528\u6237\u767b\u5f55\u5230\u60a8\u7684 Web \u5e94\u7528\u7a0b\u5e8f<\/p>\n<\/li>\n<li>\n<p>Letting users use their Facebook accounts to log in to your web app<br \/>\n\u5141\u8bb8\u7528\u6237\u4f7f\u7528\u5176 Facebook \u5e10\u6237\u767b\u5f55\u60a8\u7684 Web \u5e94\u7528\u7a0b\u5e8f<\/p>\n<\/li>\n<li>\n<p>Providing a common structure for building maintainable applications<br \/>\n\u4e3a\u6784\u5efa\u53ef\u7ef4\u62a4\u7684\u5e94\u7528\u7a0b\u5e8f\u63d0\u4f9b\u901a\u7528\u7ed3\u6784<\/p>\n<\/li>\n<li>\n<p>Reading con\ufb01guration \ufb01les Serving image \ufb01les<br \/>\n\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6\u63d0\u4f9b\u56fe\u50cf\u6587\u4ef6<\/p>\n<\/li>\n<li>\n<p>Logging requests made to your web app<br \/>\n\u8bb0\u5f55\u5bf9 Web \u5e94\u7528\u7a0b\u5e8f\u53d1\u51fa\u7684\u8bf7\u6c42<\/p>\n<\/li>\n<\/ul>\n<p>The key to any modern web application is the ability to generate dynamic web pages. A dynamic web page may display di\ufb00erent data depending on the current logged-in user, or it could display content submitted by users. Without a dynamic framework, it wouldn\u2019t be possible to log in to websites or to display any sort of personalized data on a page. In short, websites like Amazon, eBay, and Stack<\/p>\n<p>\u4efb\u4f55\u73b0\u4ee3 Web \u5e94\u7528\u7a0b\u5e8f\u7684\u5173\u952e\u662f\u751f\u6210\u52a8\u6001\u7f51\u9875\u7684\u80fd\u529b\u3002\u52a8\u6001\u7f51\u9875\u53ef\u80fd\u4f1a\u6839\u636e\u5f53\u524d\u767b\u5f55\u7684\u7528\u6237\u663e\u793a\u4e0d\u540c\u7684\u6570\u636e\uff0c\u4e5f\u53ef\u4ee5\u663e\u793a\u7528\u6237\u63d0\u4ea4\u7684\u5185\u5bb9\u3002\u5982\u679c\u6ca1\u6709\u52a8\u6001\u6846\u67b6\uff0c\u5c31\u4e0d\u53ef\u80fd\u767b\u5f55\u7f51\u7ad9\u6216\u5728\u9875\u9762\u4e0a\u663e\u793a\u4efb\u4f55\u7c7b\u578b\u7684\u4e2a\u6027\u5316\u6570\u636e\u3002\u7b80\u800c\u8a00\u4e4b\uff0cAmazon\u3001eBay \u548c Stack \u7b49\u7f51\u7ad9<\/p>\n<p>Over\ufb02ow (shown in \ufb01gure 2.1) wouldn\u2019t be possible. Web frameworks for creating dynamic web pages are almost as old as the web itself, and Microsoft has created several over the years, so why create a new one?<\/p>\n<p>\u6ea2\u51fa\uff08\u5982\u56fe 2.1 \u6240\u793a\uff09\u662f\u4e0d\u53ef\u80fd\u7684\u3002\u7528\u4e8e\u521b\u5efa\u52a8\u6001\u7f51\u9875\u7684 Web \u6846\u67b6\u51e0\u4e4e\u4e0e Web \u672c\u8eab\u4e00\u6837\u53e4\u8001\uff0cMicrosoft \u591a\u5e74\u6765\u5df2\u7ecf\u521b\u5efa\u4e86\u591a\u4e2a\u6846\u67b6\uff0c\u90a3\u4e48\u4e3a\u4ec0\u4e48\u8981\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6846\u67b6\u5462\uff1f<\/p>\n<p><img decoding=\"async\" src=\"\/images\/aspnetcoreinaction\/0201.png\" alt=\"alt text\" \/><\/p>\n<p>Figure 2.1 The Stack Over\ufb02ow website (<a href=\"https:\/\/stackover\ufb02ow.com\">https:\/\/stackover\ufb02ow.com<\/a>) is built with ASP.NET and has almost entirely dynamic content.<\/p>\n<p>\u56fe 2.1 Stack Overflow \u7f51\u7ad9 \uff08<a href=\"https:\/\/stackoverflow.com\">https:\/\/stackoverflow.com<\/a>\uff09 \u662f\u4f7f\u7528 ASP.NET \u6784\u5efa\u7684\uff0c\u51e0\u4e4e\u5b8c\u5168\u5177\u6709\u52a8\u6001\u5185\u5bb9\u3002<\/p>\n<h3>2.2 Why ASP.NET Core was created\u200c<\/h3>\n<h3>2.2 \u521b\u5efa ASP.NET Core \u7684\u539f\u56e0<\/h3>\n<p>Microsoft\u2019s development of ASP.NET Core was motivated by the desire to create a web framework with \ufb01ve main goals:<\/p>\n<p>Microsoft \u5f00\u53d1 ASP.NET Core \u7684\u52a8\u673a\u662f\u5e0c\u671b\u521b\u5efa\u4e00\u4e2a\u5177\u6709\u4e94\u4e2a\u4e3b\u8981\u76ee\u6807\u7684 Web \u6846\u67b6\uff1a<\/p>\n<ul>\n<li>\n<p>To be run and developed cross-platform<br \/>\n\u8de8\u5e73\u53f0\u8fd0\u884c\u548c\u5f00\u53d1<\/p>\n<\/li>\n<li>\n<p>To have a modular architecture for easier maintenance<br \/>\n\u91c7\u7528\u6a21\u5757\u5316\u67b6\u6784\uff0c\u66f4\u6613\u4e8e\u7ef4\u62a4<\/p>\n<\/li>\n<li>\n<p>To be developed completely as open-source software<br \/>\n\u5b8c\u5168\u4f5c\u4e3a\u5f00\u6e90\u8f6f\u4ef6\u5f00\u53d1<\/p>\n<\/li>\n<li>\n<p>To adhere to web standards<br \/>\n\u9075\u5b88 Web \u6807\u51c6<\/p>\n<\/li>\n<li>\n<p>To be applicable to current trends in web development, such as client-side applications and deployment to cloud environments<br \/>\n\u9002\u7528\u4e8e Web \u5f00\u53d1\u7684\u5f53\u524d\u8d8b\u52bf\uff0c\u4f8b\u5982\u5ba2\u6237\u7aef\u5e94\u7528\u7a0b\u5e8f\u548c\u90e8\u7f72\u5230\u4e91\u73af\u5883<\/p>\n<\/li>\n<\/ul>\n<p>To achieve all these goals, Microsoft needed a platform that could provide underlying libraries for creating basic objects such as lists and dictionaries, and for performing tasks such as simple \ufb01le operations. Up to this point, ASP.NET development had always been focused\u2014and dependent\u2014on the Windows-only .NET Framework. For ASP.NET Core, Microsoft created a lightweight platform that runs on Windows, Linux, and macOS called .NET Core (subsequently .NET), as shown in \ufb01gure 2.2.<\/p>\n<p>\u4e3a\u4e86\u5b9e\u73b0\u6240\u6709\u8fd9\u4e9b\u76ee\u6807\uff0cMicrosoft \u9700\u8981\u4e00\u4e2a\u5e73\u53f0\uff0c\u8be5\u5e73\u53f0\u53ef\u4ee5\u63d0\u4f9b\u57fa\u7840\u5e93\uff0c\u7528\u4e8e\u521b\u5efa\u57fa\u672c\u5bf9\u8c61\uff08\u5982\u5217\u8868\u548c\u5b57\u5178\uff09\u4ee5\u53ca\u6267\u884c\u4efb\u52a1\uff08\u5982\u7b80\u5355\u7684\u6587\u4ef6\u4f5c\uff09\u3002\u5728\u6b64\u4e4b\u524d\uff0cASP.NET \u5f00\u53d1\u59cb\u7ec8\u4ee5\u4ec5\u9650 Windows \u7684 .NET Framework \u4e3a\u4e2d\u5fc3\u3002\u5bf9\u4e8e ASP.NET Core\uff0cMicrosoft\u521b\u5efa\u4e86\u4e00\u4e2a\u5728 Windows\u3001Linux \u548c macOS \u4e0a\u8fd0\u884c\u7684\u8f7b\u91cf\u7ea7\u5e73\u53f0\uff0c\u79f0\u4e3a .NET Core\uff08\u968f\u540e.NET\uff09\uff0c\u5982\u56fe 2.2 \u6240\u793a\u3002<\/p>\n<p><img decoding=\"async\" src=\"\/images\/aspnetcoreinaction\/0202.png\" alt=\"alt text\" \/><\/p>\n<p>Figure 2.2 The relationships among ASP.NET Core, ASP.NET, .NET Core\/.NET 5+, and .NET Framework. ASP.NET Core runs on .NET Core and .NET 5+, so it can run cross-platform. Conversely, ASP.NET runs on .NET Framework only, so it\u2019s tied to the Windows OS.<\/p>\n<p>\u56fe 2.2 ASP.NET Core\u3001ASP.NET\u3001.NET Core\/.NET 5+ \u548c .NET Framework \u4e4b\u95f4\u7684\u5173\u7cfb\u3002ASP.NET Core \u5728 .NET Core \u548c .NET 5+ \u4e0a\u8fd0\u884c\uff0c\u56e0\u6b64\u53ef\u4ee5\u8de8\u5e73\u53f0\u8fd0\u884c\u3002\u76f8\u53cd\uff0cASP.NET \u4ec5\u5728 .NET Framework \u4e0a\u8fd0\u884c\uff0c\u56e0\u6b64\u5b83\u4e0e Windows\u4f5c\u7cfb\u7edf\u76f8\u5173\u8054\u3002<\/p>\n<p><strong>DEFINITION<\/strong> .NET 5 was the next version of .NET Core after 3.1, followed by .NET 6 and .NET 7. It represents a uni\ufb01cation of .NET Core and other .NET platforms in a single runtime and framework. It was considered to be the future of .NET.<br \/>\n<strong>\u5b9a\u4e49<\/strong> .NET 5 \u662f 3.1 \u4e4b\u540e\u7684 .NET Core \u7684\u4e0b\u4e00\u4e2a\u7248\u672c\uff0c\u5176\u6b21\u662f .NET 6 \u548c .NET 7\u3002\u5b83\u8868\u793a .NET Core \u548c\u5176\u4ed6 .NET \u5e73\u53f0\u5728\u5355\u4e2a\u8fd0\u884c\u65f6\u548c\u6846\u67b6\u4e2d\u7684\u7edf\u4e00\u3002\u5b83\u88ab\u8ba4\u4e3a\u662f .NET \u7684\u672a\u6765\u3002<\/p>\n<p>which is why Microsoft chose to drop the \u201cCore\u201d from its name. For consistency with Microsoft\u2019s language, I use the term .NET 5+ to refer to .NET 5, .NET 6, and .NET 7, and the term .NET Core to refer to previous versions.\u200c<\/p>\n<p>\u8fd9\u5c31\u662f Microsoft \u9009\u62e9\u4ece\u5176\u540d\u79f0\u4e2d\u5220\u9664\u201cCore\u201d\u7684\u539f\u56e0\u3002\u4e3a\u4e86\u4e0e Microsoft \u7684\u8bed\u8a00\u4fdd\u6301\u4e00\u81f4\uff0c\u6211\u4f7f\u7528\u672f\u8bed .NET 5+ \u6765\u6307\u4ee3 .NET 5\u3001.NET 6 \u548c .NET 7\uff0c\u4f7f\u7528\u672f\u8bed .NET Core \u6765\u6307\u4ee3\u4ee5\u524d\u7684\u7248\u672c\u3002<\/p>\n<p>.NET Core (and its successor, .NET 5+) employs many of the same APIs as .NET Framework but is more modular. It implements a di\ufb00erent set of features from those in .NET Framework, with the goal of providing a simpler programming model and modern APIs. It\u2019s a separate platform rather than a fork of .NET Framework, though it uses similar code for many of its APIs.<\/p>\n<p>.NET Core\uff08\u53ca\u5176\u540e\u7eed\u4ea7\u54c1 .NET 5+\uff09\u91c7\u7528\u8bb8\u591a\u4e0e .NET Framework \u76f8\u540c\u7684 API\uff0c\u4f46\u6a21\u5757\u5316\u7a0b\u5ea6\u66f4\u9ad8\u3002\u5b83\u5b9e\u73b0\u4e86\u4e00\u7ec4\u4e0e .NET Framework \u4e2d\u7684\u529f\u80fd\u4e0d\u540c\u7684\u529f\u80fd\uff0c\u76ee\u7684\u662f\u63d0\u4f9b\u66f4\u7b80\u5355\u7684\u7f16\u7a0b\u6a21\u578b\u548c\u73b0\u4ee3 API\u3002\u5b83\u662f\u4e00\u4e2a\u5355\u72ec\u7684\u5e73\u53f0\uff0c\u800c\u4e0d\u662f .NET Framework \u7684\u5206\u652f\uff0c\u5c3d\u7ba1\u5b83\u7684\u8bb8\u591a API \u90fd\u4f7f\u7528\u7c7b\u4f3c\u7684\u4ee3\u7801\u3002<\/p>\n<p><strong>NOTE<\/strong> If you\u2019d like to learn more about the .NET ecosystem, you can read two posts on my blog: \u201cUnderstanding the .NET ecosystem: The evolution of .NET into .NET 7\u201d (<a href=\"http:\/\/mng.bz\/Ao0W\">http:\/\/mng.bz\/Ao0W<\/a>) and \u201cUnderstanding the .NET ecosystem: The introduction of .NET Standard\u201d (<a href=\"http:\/\/mng.bz\/ZqPZ\">http:\/\/mng.bz\/ZqPZ<\/a>).<br \/>\n<strong>\u6ce8\u610f<\/strong> \u5982\u679c\u60a8\u60f3\u4e86\u89e3\u6709\u5173 .NET \u751f\u6001\u7cfb\u7edf\u7684\u66f4\u591a\u4fe1\u606f\uff0c\u53ef\u4ee5\u9605\u8bfb\u6211\u535a\u5ba2\u4e0a\u7684\u4e24\u7bc7\u6587\u7ae0\uff1a\u201c\u4e86\u89e3 .NET \u751f\u6001\u7cfb\u7edf\uff1a.NET \u5411 .NET 7 \u7684\u6f14\u53d8\u201d\uff08<a href=\"http:\/\/mng.bz\/Ao0W\">http:\/\/mng.bz\/Ao0W<\/a> \u9875\uff09\u548c\u201c\u4e86\u89e3 .NET \u751f\u6001\u7cfb\u7edf\uff1a.NET Standard \u7b80\u4ecb\u201d\uff08<a href=\"http:\/\/mng.bz\/ZqPZ\">http:\/\/mng.bz\/ZqPZ<\/a> \u9875\uff09\u3002<\/p>\n<blockquote>\n<p>The bene\ufb01ts and limitations of ASP.NET<br \/>\nASP.NET \u7684\u597d\u5904\u548c\u5c40\u9650\u6027<br \/>\nASP.NET Core is the latest evolution of Microsoft\u2019s popular ASP.NET web framework, released in June 2016. Previous versions of ASP.NET had many incremental updates, focusing on high developer productivity and prioritizing backward compatibility. ASP.NET Core bucks that trend by making signi\ufb01cant architectural changes that rethink the way the web framework is designed and built.<br \/>\nASP.NET Core \u662f Microsoft \u6d41\u884c\u7684 ASP.NET Web \u6846\u67b6\u7684\u6700\u65b0\u53d1\u5c55\u7248\u672c\uff0c\u4e8e 2016 \u5e74 6 \u6708\u53d1\u5e03\u3002\u4ee5\u524d\u7684 ASP.NET \u7248\u672c\u6709\u8bb8\u591a\u589e\u91cf\u66f4\u65b0\uff0c\u4fa7\u91cd\u4e8e\u63d0\u9ad8\u5f00\u53d1\u4eba\u5458\u7684\u5de5\u4f5c\u6548\u7387\u5e76\u4f18\u5148\u8003\u8651\u5411\u540e\u517c\u5bb9\u6027\u3002ASP.NET Core \u901a\u8fc7\u5bf9\u67b6\u6784\u8fdb\u884c\u91cd\u5927\u66f4\u6539\u6765\u91cd\u65b0\u601d\u8003 Web \u6846\u67b6\u7684\u8bbe\u8ba1\u548c\u6784\u5efa\u65b9\u5f0f\uff0c\u4ece\u800c\u9006\u52bf\u800c\u4e0a\u3002<br \/>\nASP.NET Core owes a lot to its ASP.NET heritage, and many features have been carried forward from before, but ASP.NET Core is a new framework.<br \/>\nASP.NET Core \u5728\u5f88\u5927\u7a0b\u5ea6\u4e0a\u5f52\u529f\u4e8e\u5176 ASP.NET \u4f20\u7edf\uff0c\u5e76\u4e14\u8bb8\u591a\u529f\u80fd\u90fd\u4ece\u4ee5\u524d\u7ee7\u627f\u4e86\u4e0b\u6765\uff0c\u4f46 ASP.NET Core \u662f\u4e00\u4e2a\u65b0\u6846\u67b6\u3002<br \/>\nThe whole technology stack has been rewritten, including both the web framework and the underlying platform.<br \/>\n\u6574\u4e2a\u6280\u672f\u5806\u6808\u5df2\u88ab\u91cd\u5199\uff0c\u5305\u62ec Web \u6846\u67b6\u548c\u5e95\u5c42\u5e73\u53f0\u3002<br \/>\nAt the heart of the changes is the philosophy that ASP.NET should be able to hold its head high when measured against other modern frameworks, but existing .NET developers should continue to have a sense of familiarity.<br \/>\n\u8fd9\u4e9b\u53d8\u5316\u7684\u6838\u5fc3\u7406\u5ff5\u662f\u8fd9\u6837\u4e00\u79cd\u7406\u5ff5\uff0c\u5373 ASP.NET \u4e0e\u5176\u4ed6\u73b0\u4ee3\u6846\u67b6\u76f8\u6bd4\u65f6\uff0c\u5e94\u8be5\u80fd\u591f\u6602\u9996\u633a\u80f8\uff0c\u4f46\u73b0\u6709\u7684 .NET \u5f00\u53d1\u4eba\u5458\u5e94\u8be5\u7ee7\u7eed\u4fdd\u6301\u719f\u6089\u611f\u3002<br \/>\nTo understand why Microsoft decided to build a new framework, it\u2019s important to understand the bene\ufb01ts and limitations of the legacy ASP.NET web framework.<br \/>\n\u8981\u4e86\u89e3 Microsoft \u51b3\u5b9a\u6784\u5efa\u65b0\u6846\u67b6\u7684\u539f\u56e0\uff0c\u4e86\u89e3\u65e7\u7248 ASP.NET Web \u6846\u67b6\u7684\u4f18\u52bf\u548c\u5c40\u9650\u6027\u975e\u5e38\u91cd\u8981\u3002<br \/>\nThe \ufb01rst version of ASP.NET was released in 2002 as part of .NET Framework 1.0. The ASP.NET Web Forms paradigm that it introduced di\ufb00ered signi\ufb01cantly from the conventional scripting environments of classic ASP and PHP. ASP.NET Web Forms allowed developers to create web applications rapidly by using a graphical designer and a simple event model that mirrored desktop application-building techniques.<br \/>\nASP.NET \u7684\u7b2c\u4e00\u4e2a\u7248\u672c\u4e8e 2002 \u5e74\u4f5c\u4e3a .NET Framework 1.0\u7684\u4e00\u90e8\u5206\u53d1\u5e03. \u5b83\u5f15\u5165\u7684 ASP.NET Web Forms \u8303\u4f8b\u4e0e\u4f20\u7edf ASP \u548c PHP \u7684\u4f20\u7edf\u811a\u672c\u73af\u5883\u6709\u5f88\u5927\u4e0d\u540c\u3002ASP.NET Web \u7a97\u4f53\u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u4f7f\u7528\u56fe\u5f62\u8bbe\u8ba1\u5668\u548c\u53cd\u6620\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u6784\u5efa\u6280\u672f\u7684\u7b80\u5355\u4e8b\u4ef6\u6a21\u578b\u5feb\u901f\u521b\u5efa Web \u5e94\u7528\u7a0b\u5e8f\u3002<br \/>\nThe ASP.NET framework allowed developers to create new applications quickly, but over time the web development ecosystem changed. It became apparent that ASP.NET Web Forms su\ufb00ered from many problems, especially in building larger applications. In particular, a lack of testability, a complex stateful model, and limited in\ufb02uence on the generated HTML (making client- side development di\ufb03cult) led developers to evaluate other options.<br \/>\nASP.NET \u6846\u67b6\u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u5feb\u901f\u521b\u5efa\u65b0\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u4f46\u968f\u7740\u65f6\u95f4\u7684\u63a8\u79fb\uff0cWeb \u5f00\u53d1\u751f\u6001\u7cfb\u7edf\u53d1\u751f\u4e86\u53d8\u5316\u3002\u5f88\u660e\u663e\uff0cASP.NET Web Forms \u5b58\u5728\u8bb8\u591a\u95ee\u9898\uff0c\u5c24\u5176\u662f\u5728\u6784\u5efa\u5927\u578b\u5e94\u7528\u7a0b\u5e8f\u65f6\u3002\u7279\u522b\u662f\uff0c\u7f3a\u4e4f\u53ef\u6d4b\u8bd5\u6027\u3001\u590d\u6742\u7684\u6709\u72b6\u6001\u6a21\u578b\u4ee5\u53ca\u5bf9\u751f\u6210\u7684 HTML \u7684\u6709\u9650\u5f71\u54cd\uff08\u4f7f\u5ba2\u6237\u7aef\u5f00\u53d1\u53d8\u5f97\u56f0\u96be\uff09\u5bfc\u81f4\u5f00\u53d1\u4eba\u5458\u8bc4\u4f30\u5176\u4ed6\u9009\u9879\u3002<br \/>\nIn response, Microsoft released the \ufb01rst version of ASP.NET MVC in 2009, based on the Model-View-Controller (MVC) pattern, a common web pattern used in frameworks such as Ruby on Rails, Django, and Java Spring. This framework allowed developers to separate UI elements from application logic, made testing easier, and provided tighter control of the HTML- generation process.<br \/>\n\u4f5c\u4e3a\u56de\u5e94\uff0cMicrosoft \u4e8e 2009 \u5e74\u53d1\u5e03\u4e86 ASP.NET MVC \u7684\u7b2c\u4e00\u4e2a\u7248\u672c\uff0c\u8be5\u7248\u672c\u57fa\u4e8e\u6a21\u578b-\u89c6\u56fe-\u63a7\u5236\u5668 \uff08MVC\uff09 \u6a21\u5f0f\uff0c\u8fd9\u662f Ruby on Rails\u3001Django \u548c Java Spring \u7b49\u6846\u67b6\u4e2d\u4f7f\u7528\u7684\u4e00\u79cd\u5e38\u89c1 Web \u6a21\u5f0f\u3002\u8be5\u6846\u67b6\u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u5c06 UI \u5143\u7d20\u4e0e\u5e94\u7528\u7a0b\u5e8f\u903b\u8f91\u5206\u79bb\uff0c\u4f7f\u6d4b\u8bd5\u66f4\u5bb9\u6613\uff0c\u5e76\u63d0\u4f9b\u5bf9 HTML \u751f\u6210\u8fc7\u7a0b\u7684\u66f4\u4e25\u683c\u63a7\u5236\u3002<br \/>\nASP.NET MVC has been through four more iterations since its \ufb01rst release, but all these iterations were built on the same underlying framework provided by the System .Web.dll \ufb01le. This library is part of .NET Framework, so it comes preinstalled with all versions of Windows. It contains all the core code that ASP.NET uses when you build a web application.<br \/>\nASP.NET MVC \u81ea\u9996\u6b21\u53d1\u5e03\u4ee5\u6765\u5df2\u7ecf\u7ecf\u5386\u4e86\u56db\u6b21\u8fed\u4ee3\uff0c\u4f46\u6240\u6709\u8fd9\u4e9b\u8fed\u4ee3\u90fd\u662f\u5efa\u7acb\u5728 System \u63d0\u4f9b\u7684\u76f8\u540c\u5e95\u5c42\u6846\u67b6\u4e4b\u4e0a\u7684\u3002Web.dll \u6587\u4ef6\u3002\u6b64\u5e93\u662f .NET Framework \u7684\u4e00\u90e8\u5206\uff0c\u56e0\u6b64\u5b83\u9884\u88c5\u5728\u6240\u6709\u7248\u672c\u7684 Windows \u4e2d\u3002\u5b83\u5305\u542b ASP.NET \u5728\u6784\u5efa Web \u5e94\u7528\u7a0b\u5e8f\u65f6\u4f7f\u7528\u7684\u6240\u6709\u6838\u5fc3\u4ee3\u7801\u3002<br \/>\nThis dependency brings both advantages and disadvantages. On one hand, the ASP.NET framework is a reliable, battle-tested platform that\u2019s \ufb01ne for building web applications in Windows. It provides a wide range of features that have been in production for many years, and it\u2019s well known by virtually all Windows web developers.<br \/>\n\u8fd9\u79cd\u4f9d\u8d56\u5173\u7cfb\u65e2\u6709\u4f18\u70b9\u4e5f\u6709\u7f3a\u70b9\u3002\u4e00\u65b9\u9762\uff0cASP.NET \u6846\u67b6\u662f\u4e00\u4e2a\u53ef\u9760\u7684\u3001\u7ecf\u8fc7\u5b9e\u6218\u68c0\u9a8c\u7684\u5e73\u53f0\uff0c\u975e\u5e38\u9002\u5408\u5728 Windows \u4e2d\u6784\u5efa Web \u5e94\u7528\u7a0b\u5e8f\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u5df2\u7ecf\u6295\u5165\u751f\u4ea7\u591a\u5e74\u7684\u529f\u80fd\uff0c\u51e0\u4e4e\u6240\u6709 Windows Web \u5f00\u53d1\u4eba\u5458\u90fd\u77e5\u9053\u5b83\u3002<br \/>\nOn the other hand, this reliance is limiting. Changes to the underlying System.Web.dll \ufb01le are far-reaching and, consequently, slow to roll out, which limits the extent to which ASP.NET is free to evolve and results in release cycles happening only every few years. There\u2019s also an explicit coupling with the Windows web host, Internet Information Services (IIS), which precludes its use on non-Windows platforms.<br \/>\n\u53e6\u4e00\u65b9\u9762\uff0c\u8fd9\u79cd\u4f9d\u8d56\u662f\u6709\u9650\u7684\u3002\u5bf9\u57fa\u7840 System.Web.dll \u6587\u4ef6\u7684\u66f4\u6539\u5f71\u54cd\u6df1\u8fdc\uff0c\u56e0\u6b64\u63a8\u51fa\u901f\u5ea6\u5f88\u6162\uff0c\u8fd9\u9650\u5236\u4e86 ASP.NET \u81ea\u7531\u53d1\u5c55\u7684\u7a0b\u5ea6\uff0c\u5e76\u5bfc\u81f4\u53d1\u5e03\u5468\u671f\u6bcf\u9694\u51e0\u5e74\u624d\u53d1\u751f\u4e00\u6b21\u3002\u6b64\u5916\uff0c\u8fd8\u4e0e Windows Web \u4e3b\u673a Internet Information Services \uff08IIS\uff09 \u663e\u5f0f\u8026\u5408\uff0c\u8fd9\u963b\u6b62\u4e86\u5b83\u5728\u975e Windows \u5e73\u53f0\u4e0a\u7684\u4f7f\u7528\u3002<br \/>\nMore recently, Microsoft declared .NET Framework to be \u201cdone.\u201d It won\u2019t be removed or replaced, but it also won\u2019t receive any new features.<br \/>\n\u6700\u8fd1\uff0cMicrosoft \u5ba3\u5e03 .NET Framework \u5df2\u201c\u5b8c\u6210\u201d\u3002\u5b83\u4e0d\u4f1a\u88ab\u5220\u9664\u6216\u66ff\u6362\uff0c\u4f46\u5b83\u4e5f\u4e0d\u4f1a\u83b7\u5f97\u4efb\u4f55\u65b0\u529f\u80fd\u3002<br \/>\nConsequently, ASP.NET based on System.Web.dll won\u2019t receive new features or updates either.<br \/>\n\u56e0\u6b64\uff0c\u57fa\u4e8e System.Web.dll \u7684 ASP.NET \u4e5f\u4e0d\u4f1a\u6536\u5230\u65b0\u529f\u80fd\u6216\u66f4\u65b0\u3002<br \/>\nIn recent years, many web developers have started looking at cross- platform web frameworks that can run on Windows as well as Linux and macOS. Microsoft felt the time had come to create a framework that was no longer tied to its Windows legacy; thus, ASP.NET Core was born.<br \/>\n\u8fd1\u5e74\u6765\uff0c\u8bb8\u591a Web \u5f00\u53d1\u4eba\u5458\u5f00\u59cb\u5bfb\u627e\u53ef\u4ee5\u5728 Windows \u4ee5\u53ca Linux \u548c macOS \u4e0a\u8fd0\u884c\u7684\u8de8\u5e73\u53f0 Web \u6846\u67b6\u3002Microsoft \u8ba4\u4e3a\u662f\u65f6\u5019\u521b\u5efa\u4e00\u4e2a\u4e0d\u518d\u4e0e\u5176 Windows \u4f20\u7edf\u6302\u94a9\u7684\u6846\u67b6\u4e86;\u56e0\u6b64\uff0cASP.NET Core \u8bde\u751f\u4e86\u3002<\/p>\n<\/blockquote>\n<p>With .NET 7, it\u2019s possible to build console applications that run cross-platform. Microsoft created ASP.NET Core to be an additional layer on top of console applications so that converting to a web application involves adding and composing libraries, as shown in \ufb01gure 2.3.<\/p>\n<p>\u4f7f\u7528 .NET 7\uff0c\u53ef\u4ee5\u6784\u5efa\u8de8\u5e73\u53f0\u8fd0\u884c\u7684\u63a7\u5236\u53f0\u5e94\u7528\u7a0b\u5e8f\u3002Microsoft Core \u521b\u5efa\u4e86 ASP.NET Core \u4f5c\u4e3a\u63a7\u5236\u53f0\u5e94\u7528\u7a0b\u5e8f\u4e4b\u4e0a\u7684\u9644\u52a0\u5c42\uff0c\u56e0\u6b64\u8f6c\u6362\u4e3a Web \u5e94\u7528\u7a0b\u5e8f\u6d89\u53ca\u6dfb\u52a0\u548c\u7ec4\u5408\u5e93\uff0c\u5982\u56fe 2.3 \u6240\u793a\u3002<\/p>\n<p><img decoding=\"async\" src=\"\/images\/aspnetcoreinaction\/0203.png\" alt=\"alt text\" \/><\/p>\n<p>Figure 2.3 ASP.NET Core application model. The .NET 7 platform provides a base console application model for running command-line apps. Adding a web server library converts this model to an ASP.NET Core web app. You can add other features, such as con\ufb01guration and logging, using various libraries.<\/p>\n<p>\u56fe 2.3 ASP.NET \u6838\u5fc3\u5e94\u7528\u7a0b\u5e8f\u6a21\u578b\u3002.NET 7 \u5e73\u53f0\u63d0\u4f9b\u4e86\u7528\u4e8e\u8fd0\u884c\u547d\u4ee4\u884c\u5e94\u7528\u7a0b\u5e8f\u7684\u57fa\u672c\u63a7\u5236\u53f0\u5e94\u7528\u7a0b\u5e8f\u6a21\u578b\u3002\u6dfb\u52a0 Web \u670d\u52a1\u5668\u5e93\u4f1a\u5c06\u6b64\u6a21\u578b\u8f6c\u6362\u4e3a ASP.NET Core Web \u5e94\u7528\u7a0b\u5e8f\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u5404\u79cd\u5e93\u6dfb\u52a0\u5176\u4ed6\u529f\u80fd\uff0c\u4f8b\u5982\u914d\u7f6e\u548c\u65e5\u5fd7\u8bb0\u5f55\u3002<\/p>\n<p>When you add an ASP.NET Core web server to your .NET 7 app, your console application can run as a web application.<\/p>\n<p>\u5c06 ASP.NET Core Web \u670d\u52a1\u5668\u6dfb\u52a0\u5230 .NET 7 \u5e94\u7528\u65f6\uff0c\u63a7\u5236\u53f0\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u4f5c\u4e3a Web \u5e94\u7528\u7a0b\u5e8f\u8fd0\u884c\u3002<\/p>\n<p>ASP.NET Core contains a huge number of APIs, but you\u2019ll rarely need all the features available to you. Some of the features are built in and will appear in virtually every application you create, such as the ones for reading con\ufb01guration \ufb01les or performing logging. Other features are provided by separate libraries and built on top of these base capabilities to provide application-speci\ufb01c functionality, such as third-party logins via Facebook or Google.<\/p>\n<p>ASP.NET Core \u5305\u542b\u5927\u91cf API\uff0c\u4f46\u60a8\u5f88\u5c11\u9700\u8981\u6240\u6709\u53ef\u7528\u7684\u529f\u80fd\u3002\u67d0\u4e9b\u529f\u80fd\u662f\u5185\u7f6e\u7684\uff0c\u51e0\u4e4e\u4f1a\u51fa\u73b0\u5728\u60a8\u521b\u5efa\u7684\u6bcf\u4e2a\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u4f8b\u5982\u7528\u4e8e\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6\u6216\u6267\u884c\u65e5\u5fd7\u8bb0\u5f55\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u5176\u4ed6\u529f\u80fd\u7531\u5355\u72ec\u7684\u5e93\u63d0\u4f9b\uff0c\u5e76\u57fa\u4e8e\u8fd9\u4e9b\u57fa\u672c\u529f\u80fd\u6784\u5efa\uff0c\u4ee5\u63d0\u4f9b\u7279\u5b9a\u4e8e\u5e94\u7528\u7a0b\u5e8f\u7684\u529f\u80fd\uff0c\u4f8b\u5982\u901a\u8fc7 Facebook \u6216 Google \u8fdb\u884c\u7b2c\u4e09\u65b9\u767b\u5f55\u3002<\/p>\n<p>Most of the libraries and APIs you\u2019ll use in ASP.NET Core are available on GitHub, in the Microsoft .NET organization repositories at <a href=\"https:\/\/github.com\/dotnet\/aspnetcore\">https:\/\/github.com\/dotnet\/aspnetcore<\/a>. You can \ufb01nd the core APIs there, including the authentication and logging APIs, as well as many peripheral libraries, such as the third-party authentication libraries.<\/p>\n<p>\u60a8\u5c06\u5728 ASP.NET Core \u4e2d\u4f7f\u7528\u7684\u5927\u591a\u6570\u5e93\u548c API \u90fd\u53ef\u4ee5\u5728 GitHub \u7684 Microsoft .NET \u7ec4\u7ec7\u5b58\u50a8\u5e93\u4e2d\u627e\u5230 <a href=\"https:\/\/github.com\/dotnet\/aspnetcore\u3002\u60a8\u53ef\u4ee5\u5728\u5176\u4e2d\u627e\u5230\u6838\u5fc3\">https:\/\/github.com\/dotnet\/aspnetcore\u3002\u60a8\u53ef\u4ee5\u5728\u5176\u4e2d\u627e\u5230\u6838\u5fc3<\/a> API\uff0c\u5305\u62ec\u8eab\u4efd\u9a8c\u8bc1\u548c\u65e5\u5fd7\u8bb0\u5f55 API\uff0c\u4ee5\u53ca\u8bb8\u591a\u5916\u56f4\u5e93\uff0c\u4f8b\u5982\u7b2c\u4e09\u65b9\u8eab\u4efd\u9a8c\u8bc1\u5e93\u3002<\/p>\n<p>All ASP.NET Core applications follow a similar design for basic con\ufb01guration, but in general the framework is \ufb02exible, leaving you free to create your own code conventions. These common APIs, the extension libraries that build on them, and the design conventions they promote are covered by the somewhat-nebulous term ASP.NET Core.<\/p>\n<p>\u6240\u6709 ASP.NET Core \u5e94\u7528\u7a0b\u5e8f\u90fd\u9075\u5faa\u7c7b\u4f3c\u7684\u57fa\u672c\u914d\u7f6e\u8bbe\u8ba1\uff0c\u4f46\u603b\u7684\u6765\u8bf4\uff0c\u8be5\u6846\u67b6\u662f\u7075\u6d3b\u7684\uff0c\u8ba9\u60a8\u53ef\u4ee5\u81ea\u7531\u521b\u5efa\u81ea\u5df1\u7684\u4ee3\u7801\u7ea6\u5b9a\u3002\u8fd9\u4e9b\u5e38\u89c1\u7684 API\u3001\u57fa\u4e8e\u5b83\u4eec\u7684\u6269\u5c55\u5e93\u4ee5\u53ca\u5b83\u4eec\u6240\u4fc3\u8fdb\u7684\u8bbe\u8ba1\u7ea6\u5b9a\u90fd\u5305\u542b\u5728\u6709\u70b9\u6a21\u7cca\u7684\u672f\u8bed ASP.NET Core \u4e2d\u3002<\/p>\n<h3>2.3 Understanding the many paradigms of ASP.NET Core\u200c<\/h3>\n<h3>2.3 \u4e86\u89e3 ASP.NET Core \u7684\u591a\u79cd\u8303\u5f0f<\/h3>\n<p>In chapter 1 you learned that ASP.NET Core provides a generalized web framework that can be used to build a wide variety of applications. As you may recall from section 1.2, the main paradigms are<\/p>\n<p>\u5728\u7b2c 1 \u7ae0\u4e2d\uff0c\u60a8\u4e86\u89e3\u4e86 ASP.NET Core \u63d0\u4f9b\u4e86\u4e00\u4e2a\u901a\u7528\u7684 Web \u6846\u67b6\uff0c\u53ef\u7528\u4e8e\u6784\u5efa\u5404\u79cd\u5e94\u7528\u7a0b\u5e8f\u3002\u4f60\u53ef\u80fd\u8fd8\u8bb0\u5f97 1.2 \u8282\uff0c\u4e3b\u8981\u7684\u8303\u4f8b\u662f<\/p>\n<ul>\n<li>\n<p>Minimal APIs\u2014Simple HTTP APIs that can be consumed by mobile applications or browser-based single-page applications (SPAs)<br \/>\n\u6700\u5c11\u7684 API \u2014 \u53ef\u7531\u79fb\u52a8\u5e94\u7528\u7a0b\u5e8f\u6216\u57fa\u4e8e\u6d4f\u89c8\u5668\u7684\u5355\u9875\u5e94\u7528\u7a0b\u5e8f \uff08SPA\uff09 \u4f7f\u7528\u7684\u7b80\u5355 HTTP API<\/p>\n<\/li>\n<li>\n<p>Web APIs\u2014An alternative approach for building HTTP APIs that adds more structure and features than minimal APIs<br \/>\nWeb API \u2014 \u4e00\u79cd\u6784\u5efa HTTP API \u7684\u66ff\u4ee3\u65b9\u6cd5\uff0c\u4e0e\u6700\u5c11\u7684 API \u76f8\u6bd4\uff0c\u5b83\u589e\u52a0\u4e86\u66f4\u591a\u7684\u7ed3\u6784\u548c\u529f\u80fd<\/p>\n<\/li>\n<li>\n<p>gRPC APIs\u2014Used to build e\ufb03cient binary APIs for server-to-server communication using the gRPC protocol<br \/>\ngRPC API \u2014 \u7528\u4e8e\u4f7f\u7528 gRPC \u534f\u8bae\u6784\u5efa\u9ad8\u6548\u7684\u4e8c\u8fdb\u5236 API\uff0c\u4ee5\u5b9e\u73b0\u670d\u52a1\u5668\u5230\u670d\u52a1\u5668\u7684\u901a\u4fe1<\/p>\n<\/li>\n<li>\n<p>Razor Pages\u2014Used to build page-based server- rendered applications<br \/>\nRazor Pages - \u7528\u4e8e\u6784\u5efa\u57fa\u4e8e\u9875\u9762\u7684\u670d\u52a1\u5668\u6e32\u67d3\u7684\u5e94\u7528\u7a0b\u5e8f<\/p>\n<\/li>\n<li>\n<p>MVC controllers\u2014Similar to Razor Pages; used for server-based applications but without the page- based paradigm<br \/>\nMVC \u63a7\u5236\u5668 \u2014 \u7c7b\u4f3c\u4e8e Razor Pages;\u7528\u4e8e\u57fa\u4e8e\u670d\u52a1\u5668\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u4f46\u6ca1\u6709\u57fa\u4e8e\u9875\u9762\u7684\u8303\u4f8b<\/p>\n<\/li>\n<li>\n<p>Blazor WebAssembly\u2014A browser-based SPA framework using the WebAssembly standard, similar to JavaScript frameworks such as Angular, React, and Vue<br \/>\nBlazor WebAssembly - \u4f7f\u7528 WebAssembly \u6807\u51c6\u7684\u57fa\u4e8e\u6d4f\u89c8\u5668\u7684 SPA \u6846\u67b6\uff0c\u7c7b\u4f3c\u4e8e Angular\u3001React \u548c Vue \u7b49 JavaScript \u6846\u67b6<\/p>\n<\/li>\n<li>\n<p>Blazor Server\u2014Used to build stateful applications, rendered on the server, that send UI events and page updates over WebSockets to provide the feel of a client-side SPA but with the ease of development of a server-rendered application<br \/>\nBlazor Server - \u7528\u4e8e\u6784\u5efa\u5728\u670d\u52a1\u5668\u4e0a\u5448\u73b0\u7684\u6709\u72b6\u6001\u5e94\u7528\u7a0b\u5e8f\uff0c\u8fd9\u4e9b\u5e94\u7528\u7a0b\u5e8f\u901a\u8fc7 WebSockets \u53d1\u9001 UI \u4e8b\u4ef6\u548c\u9875\u9762\u66f4\u65b0\uff0c\u4ee5\u63d0\u4f9b\u5ba2\u6237\u7aef SPA \u7684\u611f\u89c9\uff0c\u4f46\u6613\u4e8e\u5f00\u53d1\u670d\u52a1\u5668\u5448\u73b0\u7684\u5e94\u7528\u7a0b\u5e8f<\/p>\n<\/li>\n<\/ul>\n<p>All these paradigms use the core functionality of ASP.NET Core and layer the additional functionality on top. Each paradigm is suited to a di\ufb00erent style of web application or API, so some may \ufb01t better than others, depending on what sort of application you\u2019re building.<\/p>\n<p>\u6240\u6709\u8fd9\u4e9b\u8303\u4f8b\u90fd\u4f7f\u7528 ASP.NET Core \u7684\u6838\u5fc3\u529f\u80fd\uff0c\u5e76\u5c06\u9644\u52a0\u529f\u80fd\u5206\u5c42\u3002\u6bcf\u79cd\u8303\u4f8b\u90fd\u9002\u5408\u4e0d\u540c\u98ce\u683c\u7684 Web \u5e94\u7528\u7a0b\u5e8f\u6216 API\uff0c\u56e0\u6b64\u6709\u4e9b\u53ef\u80fd\u6bd4\u5176\u4ed6\u8303\u4f8b\u66f4\u9002\u5408\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u60a8\u6b63\u5728\u6784\u5efa\u7684\u5e94\u7528\u7a0b\u5e8f\u7c7b\u578b\u3002<\/p>\n<p>Traditional page-based, server-side-rendered web applications are the bread and butter of ASP.NET development, both in the previous version of ASP.NET and now in ASP.NET Core. The Razor Pages and MVC controller paradigms provide two slightly di\ufb00erent styles for building these types of applications but have many of the same concepts, as you\u2019ll see in part 2. These paradigms can be useful for building rich, dynamic websites, whether they\u2019re e- commerce sites, content management systems (CMSes), or large n-tier applications. Both the open-source CMS Orchard Core1 (\ufb01gure 2.4) and cloudscribe2 CMS project, for example, are built with ASP.NET Core.<\/p>\n<p>\u4f20\u7edf\u7684\u57fa\u4e8e\u9875\u9762\u3001\u670d\u52a1\u5668\u7aef\u5448\u73b0\u7684 Web \u5e94\u7528\u7a0b\u5e8f\u662f ASP.NET \u5f00\u53d1\u7684\u57fa\u7840\uff0c\u65e0\u8bba\u662f\u5728\u4ee5\u524d\u7684 ASP.NET \u7248\u672c\u4e2d\uff0c\u8fd8\u662f\u5728\u73b0\u5728\u7684 ASP.NET Core \u4e2d\u3002Razor Pages \u548c MVC \u63a7\u5236\u5668\u8303\u4f8b\u4e3a\u6784\u5efa\u8fd9\u4e9b\u7c7b\u578b\u7684\u5e94\u7528\u7a0b\u5e8f\u63d0\u4f9b\u4e86\u4e24\u79cd\u7565\u6709\u4e0d\u540c\u7684\u6837\u5f0f\uff0c\u4f46\u5177\u6709\u8bb8\u591a\u76f8\u540c\u7684\u6982\u5ff5\uff0c\u60a8\u5c06\u5728\u7b2c 2 \u90e8\u5206\u4e2d\u770b\u5230\u3002\u8fd9\u4e9b\u8303\u4f8b\u53ef\u7528\u4e8e\u6784\u5efa\u4e30\u5bcc\u7684\u52a8\u6001\u7f51\u7ad9\uff0c\u65e0\u8bba\u5b83\u4eec\u662f\u7535\u5b50\u5546\u52a1\u7f51\u7ad9\u3001\u5185\u5bb9\u7ba1\u7406\u7cfb\u7edf \uff08CMS\uff09 \u8fd8\u662f\u5927\u578b n \u5c42\u5e94\u7528\u7a0b\u5e8f\u3002\u4f8b\u5982\uff0c\u5f00\u6e90 CMS Orchard Core1\uff08\u56fe 2.4\uff09\u548c cloudscribe2 CMS \u9879\u76ee\u90fd\u662f\u4f7f\u7528 ASP.NET Core \u6784\u5efa\u7684\u3002<\/p>\n<p><img decoding=\"async\" src=\"\/images\/aspnetcoreinaction\/0204.png\" alt=\"alt text\" \/><\/p>\n<p>Figure 2.4 The California School Information Services website (<a href=\"https:\/\/csis.fcmat.org\">https:\/\/csis.fcmat.org<\/a>) is built with Orchard Core and ASP.NET Core.<\/p>\n<p>\u56fe 2.4 California School Information Services \u7f51\u7ad9 \uff08<a href=\"https:\/\/csis.fcmat.org\">https:\/\/csis.fcmat.org<\/a>\uff09 \u662f\u4f7f\u7528 Orchard Core \u548c ASP.NET Core \u6784\u5efa\u7684\u3002<\/p>\n<p>In addition to server-rendered applications, ASP.NET core is ideally suited to building a REST or HTTP API server. Whether you\u2019re building a mobile app, a JavaScript SPA using Angular, React, Vue, or some other client-side framework, it\u2019s easy to create an ASP.NET Core application to act as the server-side API by using both the minimal API and web API paradigms built into ASP.NET Core. You\u2019ll learn about minimal APIs in part 1 and about web APIs in chapter 20.<\/p>\n<p>\u9664\u4e86\u670d\u52a1\u5668\u6e32\u67d3\u7684\u5e94\u7528\u7a0b\u5e8f\u5916\uff0cASP.NET \u6838\u5fc3\u8fd8\u975e\u5e38\u9002\u5408\u6784\u5efa REST \u6216 HTTP API \u670d\u52a1\u5668\u3002\u65e0\u8bba\u60a8\u662f\u4f7f\u7528 Angular\u3001React\u3001Vue \u8fd8\u662f\u5176\u4ed6\u5ba2\u6237\u7aef\u6846\u67b6\u6784\u5efa\u79fb\u52a8\u5e94\u7528\u7a0b\u5e8f\u3001JavaScript SPA\uff0c\u90fd\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 ASP.NET Core \u4e2d\u5185\u7f6e\u7684\u6700\u5c0f API \u548c Web API \u8303\u4f8b\u8f7b\u677e\u521b\u5efa ASP.NET Core \u5e94\u7528\u7a0b\u5e8f\u4ee5\u5145\u5f53\u670d\u52a1\u5668\u7aef API\u3002\u60a8\u5c06\u5728\u7b2c 1 \u90e8\u5206\u4e2d\u4e86\u89e3\u6700\u5c0f API\uff0c\u5728\u7b2c 20 \u7ae0\u4e2d\u4e86\u89e3 Web API\u3002<\/p>\n<p><strong>DEFINITION<\/strong> REST stands for representational state transfer. RESTful applications typically use lightweight and stateless HTTP calls to read, post (create\/ update), and delete data.<\/p>\n<p><strong>\u5b9a\u4e49<\/strong> REST \u4ee3\u8868 representational state transfer\u3002RESTful \u5e94\u7528\u7a0b\u5e8f\u901a\u5e38\u4f7f\u7528\u8f7b\u91cf\u7ea7\u548c\u65e0\u72b6\u6001\u7684 HTTP \u8c03\u7528\u6765\u8bfb\u53d6\u3001\u53d1\u5e03\uff08\u521b\u5efa\/\u66f4\u65b0\uff09\u548c\u5220\u9664\u6570\u636e\u3002<\/p>\n<p>ASP.NET Core isn\u2019t restricted to creating RESTful services. It\u2019s easy to create a web service or remote procedure call (RPC)- style service for your application, using gRPC for example, as shown in \ufb01gure 2.5. In the simplest case, your application might expose only a single endpoint! ASP.NET Core is perfectly designed for building simple services, thanks to its cross-platform support and lightweight design.<\/p>\n<p>ASP.NET Core \u5e76\u4e0d\u5c40\u9650\u4e8e\u521b\u5efa RESTful \u670d\u52a1\u3002\u4e3a\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u521b\u5efa Web \u670d\u52a1\u6216\u8fdc\u7a0b\u8fc7\u7a0b\u8c03\u7528 \uff08RPC\uff09 \u6837\u5f0f\u7684\u670d\u52a1\u5f88\u5bb9\u6613\uff0c\u4f8b\u5982\u4f7f\u7528 gRPC\uff0c\u5982\u56fe 2.5 \u6240\u793a\u3002\u5728\u6700\u7b80\u5355\u7684\u60c5\u51b5\u4e0b\uff0c\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u53ef\u80fd\u53ea\u516c\u5f00\u4e00\u4e2a\u7aef\u70b9\uff01ASP.NET Core \u5177\u6709\u8de8\u5e73\u53f0\u652f\u6301\u548c\u8f7b\u91cf\u7ea7\u8bbe\u8ba1\uff0c\u4e13\u4e3a\u6784\u5efa\u7b80\u5355\u670d\u52a1\u800c\u8bbe\u8ba1\u3002<\/p>\n<p><strong>DEFINITION<\/strong> gRPC is a modern open-source, high- performance RPC framework. You can read more at <a href=\"https:\/\/grpc.io\">https:\/\/grpc.io<\/a>.<\/p>\n<p><strong>\u5b9a\u4e49<\/strong> gRPC \u662f\u4e00\u4e2a\u73b0\u4ee3\u7684\u5f00\u6e90\u3001\u9ad8\u6027\u80fd RPC \u6846\u67b6\u3002\u60a8\u53ef\u4ee5\u5728 <a href=\"https:\/\/grpc.io\">https:\/\/grpc.io<\/a> \u4e0a\u9605\u8bfb\u66f4\u591a\u5185\u5bb9\u3002<\/p>\n<p><img decoding=\"async\" src=\"\/images\/aspnetcoreinaction\/0205.png\" alt=\"alt text\" \/><\/p>\n<p>Figure 2.5 ASP.NET Core can act as the server-side application for a variety of clients: it can serve HTML pages for traditional web applications, act as a REST API for client-side SPA applications, or act as an ad hoc RPC service for client applications.<\/p>\n<p>\u56fe 2.5 ASP.NET Core \u53ef\u4ee5\u5145\u5f53\u5404\u79cd\u5ba2\u6237\u7aef\u7684\u670d\u52a1\u5668\u7aef\u5e94\u7528\u7a0b\u5e8f\uff1a\u5b83\u53ef\u4ee5\u4e3a\u4f20\u7edf Web \u5e94\u7528\u7a0b\u5e8f\u63d0\u4f9b HTML \u9875\u9762\uff0c\u5145\u5f53\u5ba2\u6237\u7aef SPA \u5e94\u7528\u7a0b\u5e8f\u7684 REST API\uff0c\u6216\u5145\u5f53\u5ba2\u6237\u7aef\u5e94\u7528\u7a0b\u5e8f\u7684\u4e34\u65f6 RPC \u670d\u52a1\u3002<\/p>\n<p>As well as server-rendered web apps, APIs, and gRPC endpoints, ASP.NET Core includes the Blazor framework, which can be used to build two very di\ufb00erent styles of application. Blazor WebAssembly (WASM) apps run directly in your browser, in the same way as traditional JavaScript SPA frameworks such as Angular and React. Your .NET code is compiled to WebAssembly (<a href=\"https:\/\/webassembly.org\">https:\/\/webassembly.org<\/a>) or executes on a .NET runtime compiled for WASM, and the browser downloads and runs it as it would a JavaScript app.<\/p>\n<p>\u9664\u4e86\u670d\u52a1\u5668\u5448\u73b0\u7684 Web \u5e94\u7528\u3001API \u548c gRPC \u7ec8\u7ed3\u70b9\u5916\uff0cASP.NET Core \u8fd8\u5305\u62ec Blazor \u6846\u67b6\uff0c\u8be5\u6846\u67b6\u53ef\u7528\u4e8e\u6784\u5efa\u4e24\u79cd\u622a\u7136\u4e0d\u540c\u7684\u5e94\u7528\u7a0b\u5e8f\u6837\u5f0f\u3002Blazor WebAssembly \uff08WASM\uff09 \u5e94\u7528\u76f4\u63a5\u5728\u6d4f\u89c8\u5668\u4e2d\u8fd0\u884c\uff0c\u5176\u65b9\u5f0f\u4e0e\u4f20\u7edf\u7684 JavaScript SPA \u6846\u67b6\uff08\u5982 Angular \u548c React\uff09\u76f8\u540c\u3002\u60a8\u7684 .NET \u4ee3\u7801\u88ab\u7f16\u8bd1\u4e3a WebAssembly \uff08<a href=\"https:\/\/webassembly.org\">https:\/\/webassembly.org<\/a>\uff09 \u6216\u5728\u4e3a WASM \u7f16\u8bd1\u7684 .NET \u8fd0\u884c\u65f6\u4e0a\u6267\u884c\uff0c\u6d4f\u89c8\u5668\u4f1a\u50cf\u4e0b\u8f7d JavaScript \u5e94\u7528\u7a0b\u5e8f\u4e00\u6837\u4e0b\u8f7d\u548c\u8fd0\u884c\u5b83\u3002<\/p>\n<p>This way you can build highly interactive client-side applications while using C# and all the .NET APIs and libraries you already know.<\/p>\n<p>\u8fd9\u6837\uff0c\u60a8\u5c31\u53ef\u4ee5\u5728\u4f7f\u7528 C# \u548c\u60a8\u5df2\u7ecf\u77e5\u9053\u7684\u6240\u6709 .NET API \u548c\u5e93\u7684\u540c\u65f6\u6784\u5efa\u9ad8\u5ea6\u4ea4\u4e92\u7684\u5ba2\u6237\u7aef\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>By contrast, Blazor Server applications run on the server. Each mouse click or keyboard event is sent to the server via WebSockets. Then the server calculates the changes that should be made to the UI and sends the required changes back to the client, which updates the page in the browser.<\/p>\n<p>\u76f8\u6bd4\u4e4b\u4e0b\uff0cBlazor Server \u5e94\u7528\u7a0b\u5e8f\u5728\u670d\u52a1\u5668\u4e0a\u8fd0\u884c\u3002\u6bcf\u4e2a\u9f20\u6807\u5355\u51fb\u6216\u952e\u76d8\u4e8b\u4ef6\u90fd\u901a\u8fc7 WebSockets \u53d1\u9001\u5230\u670d\u52a1\u5668\u3002\u7136\u540e\uff0c\u670d\u52a1\u5668\u8ba1\u7b97\u5e94\u8be5\u5bf9 UI \u8fdb\u884c\u7684\u66f4\u6539\uff0c\u5e76\u5c06\u6240\u9700\u7684\u66f4\u6539\u53d1\u9001\u56de\u5ba2\u6237\u7aef\uff0c\u5ba2\u6237\u7aef\u4f1a\u5728\u6d4f\u89c8\u5668\u4e2d\u66f4\u65b0\u9875\u9762\u3002<\/p>\n<p>The result is a \u201cstateful\u201d application that runs server-side but can be used to build highly interactive SPAs. The main downside of Blazor Server is that it requires a constant internet connection.<\/p>\n<p>\u7ed3\u679c\u662f\u4e00\u4e2a\u201c\u6709\u72b6\u6001\u201d\u5e94\u7528\u7a0b\u5e8f\uff0c\u5b83\u5728\u670d\u52a1\u5668\u7aef\u8fd0\u884c\uff0c\u4f46\u53ef\u7528\u4e8e\u6784\u5efa\u9ad8\u5ea6\u4ea4\u4e92\u7684 SPA\u3002Blazor Server \u7684\u4e3b\u8981\u7f3a\u70b9\u662f\u5b83\u9700\u8981\u6301\u7eed\u7684 Internet \u8fde\u63a5\u3002<\/p>\n<p><strong>NOTE<\/strong> In this book I focus on building traditional page-based, server-side- rendered web applications and RESTful web APIs. I also show how to create background worker services in chapter 34. For more information on Blazor, I recommend Blazor in Action, by Chris Sainty (Manning, 2022).\u200c<\/p>\n<p><strong>\u6ce8\u610f<\/strong> \u5728\u8fd9\u672c\u4e66\u4e2d\uff0c\u6211\u91cd\u70b9\u4ecb\u7ecd\u4e86\u5982\u4f55\u6784\u5efa\u4f20\u7edf\u7684\u57fa\u4e8e\u9875\u9762\u3001\u670d\u52a1\u5668\u7aef\u6e32\u67d3\u7684 Web \u5e94\u7528\u7a0b\u5e8f\u548c RESTful Web API\u3002\u6211\u8fd8\u5728 Chapter 34 \u4e2d\u5c55\u793a\u4e86\u5982\u4f55\u521b\u5efa\u540e\u53f0 worker \u670d\u52a1\u3002\u6709\u5173 Blazor \u7684\u66f4\u591a\u4fe1\u606f\uff0c\u6211\u63a8\u8350 Chris Sainty \u7684 Blazor in Action\uff08\u66fc\u5b81\uff0c2022 \u5e74\uff09\u3002<\/p>\n<p>With the ability to call on all these paradigms, you can use ASP.NET Core to build a wide variety of applications, but it\u2019s still worth considering whether ASP.NET Core is right for your speci\ufb01c application. That decision will likely be a\ufb00ected by both your experience with .NET and the application you want to build.<br \/>\n\u7531\u4e8e\u80fd\u591f\u8c03\u7528\u6240\u6709\u8fd9\u4e9b\u8303\u5f0f\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 ASP.NET Core \u6784\u5efa\u5404\u79cd\u5e94\u7528\u7a0b\u5e8f\uff0c\u4f46\u4ecd\u7136\u503c\u5f97\u8003\u8651 ASP.NET Core \u662f\u5426\u9002\u5408\u60a8\u7279\u5b9a\u5e94\u7528\u3002\u8be5\u51b3\u5b9a\u53ef\u80fd\u4f1a\u53d7\u5230\u60a8\u5bf9 .NET \u7684\u4f53\u9a8c\u548c\u8981\u6784\u5efa\u7684\u5e94\u7528\u7a0b\u5e8f\u7684\u5f71\u54cd\u3002<\/p>\n<h3>2.4 When to choose ASP.NET Core\u200c<\/h3>\n<h3>2.4 \u4f55\u65f6\u9009\u62e9 ASP.NET Core<\/h3>\n<p>In this section I\u2019ll describe some of the points to consider when deciding whether to use ASP.NET Core and .NET 7 instead of legacy .NET Framework ASP.NET. In most cases the decision will be to use ASP.NET Core, but you should consider some important caveats.<\/p>\n<p>\u5728\u672c\u8282\u4e2d\uff0c\u6211\u5c06\u4ecb\u7ecd\u5728\u51b3\u5b9a\u662f\u5426\u4f7f\u7528 ASP.NET Core \u548c .NET 7 \u800c\u4e0d\u662f\u65e7\u7248 .NET Framework ASP.NET \u65f6\u8981\u8003\u8651\u7684\u4e00\u4e9b\u8981\u70b9\u3002\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u60a8\u51b3\u5b9a\u4f7f\u7528 ASP.NET Core\uff0c\u4f46\u60a8\u5e94\u8be5\u8003\u8651\u4e00\u4e9b\u91cd\u8981\u7684\u6ce8\u610f\u4e8b\u9879\u3002<\/p>\n<p>When choosing a platform, you should consider multiple factors, not all of which are technical. One such factor is the level of support you can expect to receive from its creators. For some organizations, limited support can be one of the main obstacles to adopting open-source software. Luckily, Microsoft has pledged to provide full support for Long Term Support (LTS) versions of .NET and ASP.NET Core for at least three years from the time of their release. And as all development takes place in the open, sometimes you can get answers to your questions from the general community as well as from Microsoft directly.<\/p>\n<p>\u9009\u62e9\u5e73\u53f0\u65f6\uff0c\u60a8\u5e94\u8be5\u8003\u8651\u591a\u4e2a\u56e0\u7d20\uff0c\u5e76\u975e\u6240\u6709\u56e0\u7d20\u90fd\u662f\u6280\u672f\u56e0\u7d20\u3002\u5176\u4e2d\u4e00\u4e2a\u56e0\u7d20\u662f\u60a8\u53ef\u4ee5\u671f\u671b\u4ece\u5176\u521b\u5efa\u8005\u90a3\u91cc\u83b7\u5f97\u7684\u652f\u6301\u6c34\u5e73\u3002\u5bf9\u4e8e\u67d0\u4e9b\u7ec4\u7ec7\u6765\u8bf4\uff0c\u6709\u9650\u7684\u652f\u6301\u53ef\u80fd\u662f\u91c7\u7528\u5f00\u6e90\u8f6f\u4ef6\u7684\u4e3b\u8981\u969c\u788d\u4e4b\u4e00\u3002\u5e78\u8fd0\u7684\u662f\uff0cMicrosoft \u5df2\u627f\u8bfa\u4e3a .NET \u548c ASP.NET Core \u7684\u957f\u671f\u652f\u6301 \uff08LTS\uff09 \u7248\u672c\u63d0\u4f9b\u5168\u9762\u652f\u6301\uff0c\u4ece\u53d1\u5e03\u4e4b\u65e5\u8d77\u81f3\u5c11\u4e09\u5e74\u3002\u7531\u4e8e\u6240\u6709\u5f00\u53d1\u90fd\u662f\u5728\u516c\u5f00\u73af\u5883\u4e2d\u8fdb\u884c\u7684\uff0c\u56e0\u6b64\u6709\u65f6\u60a8\u53ef\u4ee5\u4ece\u4e00\u822c\u793e\u533a\u4ee5\u53ca\u76f4\u63a5\u4ece Microsoft \u83b7\u5f97\u95ee\u9898\u7684\u7b54\u6848\u3002<\/p>\n<p><strong>NOTE<\/strong> You can view Microsoft\u2019s o\ufb03cial support policy at <a href=\"http:\/\/mng.bz\/RxXP\">http:\/\/mng.bz\/RxXP<\/a>.<\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong> \u60a8\u53ef\u4ee5\u5728 <a href=\"http:\/\/mng.bz\/RxXP\">http:\/\/mng.bz\/RxXP<\/a> \u67e5\u770b Microsoft \u7684\u5b98\u65b9\u652f\u6301\u653f\u7b56\u3002<\/p>\n<p>When deciding whether to use ASP.NET Core, you have two primary dimensions to consider: whether you\u2019re already a .NET developer and whether you\u2019re creating a new application or looking to convert an existing one.<\/p>\n<p>\u5728\u51b3\u5b9a\u662f\u5426\u4f7f\u7528 ASP.NET Core \u65f6\uff0c\u60a8\u9700\u8981\u8003\u8651\u4e24\u4e2a\u4e3b\u8981\u65b9\u9762\uff1a\u60a8\u662f\u5426\u5df2\u7ecf\u662f.NET \u5f00\u53d1\u4eba\u5458\uff0c\u65e0\u8bba\u60a8\u662f\u8981\u521b\u5efa\u65b0\u5e94\u7528\u7a0b\u5e8f\u8fd8\u662f\u5e0c\u671b\u8f6c\u6362\u73b0\u6709\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<h4>2.4.1 If you\u2019re new to .NET development\u200c<\/h4>\n<h4>2.4.1 \u5982\u679c\u60a8\u4e0d\u719f\u6089 .NET \u5f00\u53d1<\/h4>\n<p>If you\u2019re new to .NET development, you\u2019re joining at a great time! Many of the growing pains associated with a new framework have been worked out, and the result is a stable, high-performance, cross-platform application framework.<\/p>\n<p>\u5982\u679c\u4f60\u662f .NET \u5f00\u53d1\u7684\u65b0\u624b\uff0c\u90a3\u4e48\u52a0\u5165\u7684\u65f6\u673a\u6b63\u597d\uff01\u4e0e\u65b0\u6846\u67b6\u76f8\u5173\u7684\u8bb8\u591a\u6210\u957f\u4e4b\u75db\u5df2\u7ecf\u89e3\u51b3\uff0c\u7ed3\u679c\u662f\u4e00\u4e2a\u7a33\u5b9a\u3001\u9ad8\u6027\u80fd\u3001\u8de8\u5e73\u53f0\u7684\u5e94\u7528\u7a0b\u5e8f\u6846\u67b6\u3002<\/p>\n<p>The primary language of .NET development, and of ASP.NET Core in particular, is C#. This language has a huge following, for good reason! As an object-oriented C-based language, it provides a sense of familiarity to those who are used to C, Java, and many other languages. In addition, it has many powerful features, such as Language Integrated Query (LINQ), closures, and asynchronous programming constructs. The C# language is also designed in the open on GitHub, as is Microsoft\u2019s C# compiler, code-named Roslyn (<a href=\"https:\/\/github.com\/dotnet\/roslyn\">https:\/\/github.com\/dotnet\/roslyn<\/a>).<\/p>\n<p>.NET \u5f00\u53d1\uff08\u5c24\u5176\u662f ASP.NET Core \u7684\u4e3b\u8981\u8bed\u8a00\uff09\u662f C#\u3002\u8fd9\u79cd\u8bed\u8a00\u6709\u5927\u91cf\u7684\u8ffd\u968f\u8005\uff0c\u8fd9\u662f\u6709\u5145\u5206\u7406\u7531\u7684\uff01\u4f5c\u4e3a\u4e00\u79cd\u9762\u5411\u5bf9\u8c61\u7684\u57fa\u4e8e C \u8bed\u8a00\uff0c\u5b83\u4e3a\u4e60\u60ef\u4e86 C\u3001Java \u548c\u8bb8\u591a\u5176\u4ed6\u8bed\u8a00\u7684\u4eba\u63d0\u4f9b\u4e86\u4e00\u79cd\u719f\u6089\u611f\u3002\u6b64\u5916\uff0c\u5b83\u8fd8\u5177\u6709\u8bb8\u591a\u5f3a\u5927\u7684\u529f\u80fd\uff0c\u4f8b\u5982\u8bed\u8a00\u96c6\u6210\u67e5\u8be2 \uff08LINQ\uff09\u3001\u95ed\u5305\u548c\u5f02\u6b65\u7f16\u7a0b\u7ed3\u6784\u3002C# \u8bed\u8a00\u4e5f\u662f\u5728 GitHub \u4e0a\u516c\u5f00\u8bbe\u8ba1\u7684\uff0cMicrosoft \u7684 C# \u7f16\u8bd1\u5668\uff0c\u4ee3\u53f7\u4e3a Roslyn \uff08<a href=\"https:\/\/github.com\/dotnet\/roslyn\">https:\/\/github.com\/dotnet\/roslyn<\/a>\uff09\u3002<\/p>\n<p><strong>NOTE<\/strong> I use C# throughout this book and will highlight some of the newer features it provides, but I won\u2019t be teaching the language from scratch. If you want to learn C#, I recommend C# in Depth, 4th ed., by Jon Skeet (Manning, 2019), and Code Like a Pro in C#, by Jort Rodenburg (Manning, 2021).\u200c\u200c\u200c<\/p>\n<p><strong>\u6ce8\u610f<\/strong> \u6211\u5728\u672c\u4e66\u4e2d\u90fd\u4f7f\u7528\u4e86 C#\uff0c\u5e76\u5c06\u91cd\u70b9\u4ecb\u7ecd\u5b83\u63d0\u4f9b\u7684\u4e00\u4e9b\u65b0\u529f\u80fd\uff0c\u4f46\u6211\u4e0d\u4f1a\u4ece\u5934\u5f00\u59cb\u6559\u6388\u8fd9\u95e8\u8bed\u8a00\u3002\u5982\u679c\u60a8\u60f3\u5b66\u4e60 C#\uff0c\u6211\u63a8\u8350 Jon Skeet \u7684 C# in Depth\uff0c\u7b2c 4 \u7248\uff08Manning\uff0c2019 \u5e74\uff09\u548c Jort Rodenburg \u7684 Code Like a Pro in C#\uff08Manning\uff0c2021 \u5e74\uff09\u3002<\/p>\n<p>One big advantage of ASP.NET Core and .NET 7 over .NET Framework is that they enable you to develop and run on any platform. With .NET 7 you can build and run the same application on Mac, Windows, and Linux, and even deploy to the cloud using tiny container deployments.<br \/>\n\u4e0e .NET Framework \u76f8\u6bd4\uff0cASP.NET Core \u548c .NET 7 \u7684\u4e00\u5927\u4f18\u52bf\u662f\uff0c\u5b83\u4eec\u4f7f\u60a8\u80fd\u591f\u5728\u4efb\u4f55\u5e73\u53f0\u4e0a\u8fdb\u884c\u5f00\u53d1\u548c\u8fd0\u884c\u3002\u4f7f\u7528 .NET 7\uff0c\u60a8\u53ef\u4ee5\u6784\u5efa\u548c\u8fd0\u884c\u76f8\u540c\u7684Mac\u3001Windows \u548c Linux \u4e0a\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u751a\u81f3\u53ef\u4ee5\u4f7f\u7528\u5fae\u578b\u5bb9\u5668\u90e8\u7f72\u90e8\u7f72\u5230\u4e91\u4e2d\u3002<\/p>\n<blockquote>\n<p>Built with containers in mind<br \/>\n\u4ee5\u5bb9\u5668\u4e3a\u6784\u5efa\u7406\u5ff5<br \/>\nTraditionally, web applications were deployed directly to a server or, more recently, to a virtual machine. Virtual machines allow operating systems to be installed in a layer of virtual hardware, abstracting away the underlying hardware. This approach has several advantages over direct installation, such as easy maintenance, deployment, and recovery. Unfortunately, virtual machines are also heavy, in terms of both \ufb01le size and resource use.<br \/>\n\u4f20\u7edf\u4e0a\uff0cWeb \u5e94\u7528\u7a0b\u5e8f\u76f4\u63a5\u90e8\u7f72\u5230\u670d\u52a1\u5668\uff0c\u6216\u8005\u6700\u8fd1\u90e8\u7f72\u5230\u865a\u62df\u673a\u3002\u865a\u62df\u673a\u5141\u8bb8\u5c06\u4f5c\u7cfb\u7edf\u5b89\u88c5\u5728\u865a\u62df\u786c\u4ef6\u5c42\u4e2d\uff0c\u4ece\u800c\u62bd\u8c61\u51fa\u5e95\u5c42\u786c\u4ef6\u3002\u4e0e\u76f4\u63a5\u5b89\u88c5\u76f8\u6bd4\uff0c\u6b64\u65b9\u6cd5\u5177\u6709\u591a\u4e2a\u4f18\u70b9\uff0c\u4f8b\u5982\u6613\u4e8e\u7ef4\u62a4\u3001\u90e8\u7f72\u548c\u6062\u590d\u3002\u9057\u61be\u7684\u662f\uff0c\u865a\u62df\u673a\u5728\u6587\u4ef6\u5927\u5c0f\u548c\u8d44\u6e90\u4f7f\u7528\u65b9\u9762\u4e5f\u5f88\u7e41\u91cd\u3002<br \/>\nThis is where containers come in. Containers are far more lightweight and don\u2019t have the overhead of virtual machines. They\u2019re built in a series of layers and don\u2019t require you to boot a new operating system when starting a new one, so they\u2019re quick to start and great for quick provisioning.Containers (Docker in particular) are quickly becoming the go-to platform for building large, scalable systems.<br \/>\n\u8fd9\u5c31\u662f\u5bb9\u5668\u7684\u7528\u6b66\u4e4b\u5730\u3002\u5bb9\u5668\u7684\u8f7b\u91cf\u7ea7\u8981\u8f7b\u5f97\u591a\uff0c\u5e76\u4e14\u6ca1\u6709\u865a\u62df\u673a\u7684\u5f00\u9500\u3002\u5b83\u4eec\u6784\u5efa\u5728\u4e00\u7cfb\u5217\u5c42\u4e2d\uff0c\u5728\u542f\u52a8\u65b0\u4f5c\u7cfb\u7edf\u65f6\u4e0d\u9700\u8981\u542f\u52a8\u65b0\u4f5c\u7cfb\u7edf\uff0c\u56e0\u6b64\u5b83\u4eec\u53ef\u4ee5\u5feb\u901f\u542f\u52a8\uff0c\u975e\u5e38\u9002\u5408\u5feb\u901f\u914d\u7f6e\u3002\u5bb9\u5668\uff08\u5c24\u5176\u662f Docker\uff09\u6b63\u8fc5\u901f\u6210\u4e3a\u6784\u5efa\u5927\u578b\u53ef\u6269\u5c55\u7cfb\u7edf\u7684\u9996\u9009\u5e73\u53f0\u3002<br \/>\nContainers have never been a particularly attractive option for ASP.NET applications, but with ASP.NET Core, .NET 7, and Docker for Windows, all that is changing. A lightweight ASP.NET Core application running on the cross-platform .NET 7 framework is perfect for thin container deployments. You can learn more about your deployment options in chapter 27.<br \/>\n\u5bb9\u5668\u4ece\u6765\u90fd\u4e0d\u662f ASP.NET \u5e94\u7528\u7a0b\u5e8f\u7279\u522b\u6709\u5438\u5f15\u529b\u7684\u9009\u62e9\uff0c\u4f46\u968f\u7740 ASP.NET Core\u3001.NET 7 \u548c Docker for Windows \u7684\u63a8\u51fa\uff0c\u8fd9\u4e00\u5207\u90fd\u53d1\u751f\u4e86\u53d8\u5316\u3002\u5728\u8de8\u5e73\u53f0 .NET 7 \u6846\u67b6\u4e0a\u8fd0\u884c\u7684\u8f7b\u91cf\u7ea7 ASP.NET Core \u5e94\u7528\u7a0b\u5e8f\u975e\u5e38\u9002\u5408\u7626\u5bb9\u5668\u90e8\u7f72\u3002\u60a8\u53ef\u4ee5\u5728\u7b2c 27 \u7ae0\u4e2d\u4e86\u89e3\u6709\u5173\u90e8\u7f72\u9009\u9879\u7684\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n<\/blockquote>\n<p>In addition to running on each platform, one of the selling points of .NET is your ability to write and compile only once. Your application is compiled to Intermediate Language (IL) code, which is a platform-independent format. If a target system has the .NET 7 runtime installed, you can run compiled IL from any platform. You can develop on a Mac or a Windows machine, for example, and deploy exactly the same \ufb01les to your production Linux machines. This compile-once, run-anywhere promise has \ufb01nally been realized with ASP.NET Core and .NET 7.<br \/>\n\u9664\u4e86\u5728\u6bcf\u4e2a\u5e73\u53f0\u4e0a\u8fd0\u884c\u4e4b\u5916\uff0c.NET \u7684\u5356\u70b9\u4e4b\u4e00\u662f\u60a8\u80fd\u591f\u53ea\u7f16\u5199\u548c\u7f16\u8bd1\u4e00\u6b21\u3002\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u88ab\u7f16\u8bd1\u4e3a\u4e2d\u95f4\u8bed\u8a00 \uff08IL\uff09 \u4ee3\u7801\uff0c\u8fd9\u662f\u4e00\u79cd\u4e0e\u5e73\u53f0\u65e0\u5173\u7684\u683c\u5f0f\u3002\u5982\u679c\u76ee\u6807\u7cfb\u7edf\u5b89\u88c5\u4e86 .NET 7 \u8fd0\u884c\u65f6\uff0c\u5219\u53ef\u4ee5\u4ece\u4efb\u4f55\u5e73\u53f0\u8fd0\u884c\u7f16\u8bd1\u7684 IL\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u5728 Mac \u6216 Windows \u8ba1\u7b97\u673a\u4e0a\u8fdb\u884c\u5f00\u53d1\uff0c\u5e76\u5c06\u5b8c\u5168\u76f8\u540c\u7684\u6587\u4ef6\u90e8\u7f72\u5230\u751f\u4ea7 Linux \u8ba1\u7b97\u673a\u4e0a\u3002\u201c\u4e00\u6b21\u7f16\u5199,\u5230\u5904\u8fd0\u884c\u201d\u7684\u627f\u8bfa\u7ec8\u4e8e\u5728 ASP.NET Core \u548c .NET 7 \u4e2d\u5b9e\u73b0\u4e86\u3002<\/p>\n<p><strong>TIP<\/strong> You can go one step further and package the .NET runtime with your app in a so-called self-contained deployment (SCD). This way, you can deploy cross-platform, and the target machine doesn\u2019t even need .NET installed.<br \/>\nWith SCDs, the generated deployment \ufb01les are customized for the target machine, so you\u2019re no longer deploying the same \ufb01les everywhere in this case.<\/p>\n<p><strong>\u63d0\u793a<\/strong> \u60a8\u53ef\u4ee5\u66f4\u8fdb\u4e00\u6b65\uff0c\u5c06 .NET \u8fd0\u884c\u65f6\u4e0e\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u5230\u6240\u8c13\u7684\u81ea\u5305\u542b\u90e8\u7f72 \uff08SCD\uff09 \u4e2d\u3002\u8fd9\u6837\uff0c\u60a8\u53ef\u4ee5\u8de8\u5e73\u53f0\u90e8\u7f72\uff0c\u5e76\u4e14\u76ee\u6807\u8ba1\u7b97\u673a\u751a\u81f3\u4e0d\u9700\u8981\u5b89\u88c5 .NET\u3002\u4f7f\u7528 SCD \u65f6\uff0c\u751f\u6210\u7684\u90e8\u7f72\u6587\u4ef6\u4f1a\u9488\u5bf9\u76ee\u6807\u8ba1\u7b97\u673a\u8fdb\u884c\u81ea\u5b9a\u4e49\uff0c\u56e0\u6b64\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u60a8\u4e0d\u518d\u9700\u8981\u5728\u4efb\u4f55\u5730\u65b9\u90e8\u7f72\u76f8\u540c\u7684\u6587\u4ef6\u3002<\/p>\n<p>Many of the web frameworks available today use similar well-established design patterns, and ASP.NET Core is no di\ufb00erent. Ruby on Rails, for example, is known for its use of the MVC pattern; Node.js is known for the way it processes requests using small discrete modules (called a pipeline); and dependency injection is available in a wide variety of frameworks. If these techniques are familiar to you, you should \ufb01nd it easy to transfer them to ASP.NET Core; if they\u2019re new to you, you can look forward to using industry best practices!<\/p>\n<p>\u5f53\u4eca\u53ef\u7528\u7684\u8bb8\u591a Web \u6846\u67b6\u90fd\u4f7f\u7528\u7c7b\u4f3c\u7684\u6210\u719f\u8bbe\u8ba1\u6a21\u5f0f\uff0cASP.NET Core \u4e5f\u4e0d\u4f8b\u5916\u3002\u4f8b\u5982\uff0cRuby on Rails \u4ee5\u5176\u5bf9 MVC \u6a21\u5f0f\u7684\u4f7f\u7528\u800c\u95fb\u540d;Node.js \u4ee5\u5176\u4f7f\u7528\u5c0f\u578b\u79bb\u6563\u6a21\u5757\uff08\u79f0\u4e3a\u7ba1\u9053\uff09\u5904\u7406\u8bf7\u6c42\u7684\u65b9\u5f0f\u800c\u95fb\u540d;\u4f9d\u8d56\u9879\u6ce8\u5165\u53ef\u7528\u4e8e\u5404\u79cd\u6846\u67b6\u3002\u5982\u679c\u60a8\u719f\u6089\u8fd9\u4e9b\u6280\u672f\uff0c\u60a8\u5e94\u8be5\u4f1a\u53d1\u73b0\u5c06\u5b83\u4eec\u4f20\u8f93\u5230 ASP.NET Core \u5f88\u5bb9\u6613;\u5982\u679c\u60a8\u5bf9\u4ed6\u4eec\u4e0d\u719f\u6089\uff0c\u60a8\u53ef\u4ee5\u671f\u5f85\u4f7f\u7528\u884c\u4e1a\u6700\u4f73\u5b9e\u8df5\uff01<\/p>\n<p><strong>NOTE<\/strong> Design patterns are solutions to common software design problems. You\u2019ll encounter a pipeline in chapter 4, dependency injection in chapters 8 and 9, and MVC in chapter 19.<\/p>\n<p><strong>\u6ce8\u610f<\/strong> \u8bbe\u8ba1\u6a21\u5f0f\u662f\u5e38\u89c1\u8f6f\u4ef6\u8bbe\u8ba1\u95ee\u9898\u7684\u89e3\u51b3\u65b9\u6848\u3002\u60a8\u5c06\u5728\u7b2c 4 \u7ae0\u4e2d\u9047\u5230\u7ba1\u9053\uff0c\u5728\u7b2c 8 \u7ae0\u548c\u7b2c 9 \u7ae0\u4e2d\u9047\u5230\u4f9d\u8d56\u5173\u7cfb\u6ce8\u5165\uff0c\u5728\u7b2c 19 \u7ae0\u4e2d\u9047\u5230 MVC\u3002<\/p>\n<p>Whether you\u2019re new to web development generally or only with .NET, ASP.NET Core provides a rich set of features with which you can build applications but doesn\u2019t overwhelm you with concepts, as the legacy ASP.NET framework did. On the other hand, if you\u2019re familiar with .NET, it\u2019s worth considering whether now is the time to take a look at ASP.NET Core.<\/p>\n<p>\u65e0\u8bba\u4f60\u662f\u4e00\u822c\u7684 Web \u5f00\u53d1\u65b0\u624b\uff0c\u8fd8\u662f\u53ea\u4f7f\u7528 .NET\uff0cASP.NET Core \u90fd\u63d0\u4f9b\u4e86\u4e00\u7ec4\u4e30\u5bcc\u7684\u529f\u80fd\uff0c\u4f60\u53ef\u4ee5\u5229\u7528\u8fd9\u4e9b\u529f\u80fd\u6784\u5efa\u5e94\u7528\u7a0b\u5e8f\uff0c\u4f46\u4e0d\u4f1a\u50cf\u65e7\u7248 ASP.NET \u6846\u67b6\u90a3\u6837\u88ab\u6982\u5ff5\u6240\u6df9\u6ca1\u3002\u5728\u53e6\u4e00\u65b9\u9762\uff0c\u5982\u679c\u60a8\u719f\u6089 .NET\uff0c\u5219\u503c\u5f97\u8003\u8651\u73b0\u5728\u662f\u5426\u662f\u4e86\u89e3 ASP.NET Core \u7684\u65f6\u5019\u3002<\/p>\n<h4>2.4.2 If you\u2019re a .NET Framework developer creating a new application\u200c<\/h4>\n<h4>2.4.2 \u5982\u679c\u60a8\u662f\u521b\u5efa\u65b0\u5e94\u7528\u7a0b\u5e8f\u7684 .NET Framework \u5f00\u53d1\u4eba\u5458<\/h4>\n<p>If you\u2019re already a .NET Framework developer, you\u2019ve likely been aware of .NET Core and ASP.NET Core, but perhaps you were wary about jumping in too soon or didn\u2019t want to hit the inevitable \u201cversion 1\u201d problems. The good news is that ASP.NET Core and .NET are now mature, stable platforms, and it\u2019s absolutely time to consider using .NET 7 for your new apps.<\/p>\n<p>\u5982\u679c\u60a8\u5df2\u7ecf\u662f .NET Framework \u5f00\u53d1\u4eba\u5458\uff0c\u60a8\u53ef\u80fd\u5df2\u7ecf\u4e86\u89e3 .NET Core \u548c ASP.NET Core\uff0c\u4f46\u4e5f\u8bb8\u60a8\u62c5\u5fc3\u8fc7\u65e9\u52a0\u5165\uff0c\u6216\u8005\u4e0d\u60f3\u9047\u5230\u4e0d\u53ef\u907f\u514d\u7684\u201c\u7248\u672c 1\u201d\u95ee\u9898\u3002\u597d\u6d88\u606f\u662f\uff0cASP.NET Core \u548c .NET \u73b0\u5728\u662f\u6210\u719f\u3001\u7a33\u5b9a\u7684\u5e73\u53f0\uff0c\u7edd\u5bf9\u662f\u65f6\u5019\u8003\u8651\u5c06 .NET 7 \u7528\u4e8e\u60a8\u7684\u65b0\u5e94\u7528\u7a0b\u5e8f\u4e86\u3002<\/p>\n<p>As a .NET developer, if you aren\u2019t using any Windows-speci\ufb01c constructs such as the Registry, the ability to build and deploy cross-platform opens the possibility for cheaper Linux hosting in the cloud, or for developing natively in macOS without the need for a virtual machine.<\/p>\n<p>\u4f5c\u4e3a .NET \u5f00\u53d1\u4eba\u5458\uff0c\u5982\u679c\u60a8\u4e0d\u4f7f\u7528\u4efb\u4f55\u7279\u5b9a\u4e8e Windows \u7684\u7ed3\u6784\uff08\u5982\u6ce8\u518c\u8868\uff09\uff0c\u5219\u6784\u5efa\u548c\u90e8\u7f72\u8de8\u5e73\u53f0\u7684\u80fd\u529b\u4e3a\u5728\u4e91\u4e2d\u6258\u7ba1 Linux \u6216\u65e0\u9700\u865a\u62df\u673a\u5373\u53ef\u5728 macOS \u4e2d\u8fdb\u884c\u672c\u673a\u5f00\u53d1\u63d0\u4f9b\u4e86\u53ef\u80fd\u6027\u3002<\/p>\n<p>.NET Core and .NET 7 are inherently cross-platform, but you can still use platform-speci\ufb01c features if you need to.Windows-speci\ufb01c features such as the Registry and Directory Services, for example, can be enabled with a Compatibility Pack that makes these APIs available in .NET 5+. They\u2019re available only when running .NET 5+ in Windows, not Linux or macOS, so you need to take care that such applications run only in a Windows environment or account for the potential missing APIs.<\/p>\n<p>.NET Core \u548c .NET 7 \u672c\u8d28\u4e0a\u662f\u8de8\u5e73\u53f0\u7684\uff0c\u4f46\u5982\u679c\u9700\u8981\uff0c\u4f60\u4ecd\u7136\u53ef\u4ee5\u4f7f\u7528\u7279\u5b9a\u4e8e\u5e73\u53f0\u7684\u529f\u80fd\u3002\u7279\u5b9a\u4e8e Windows \u7684\u529f\u80fd\uff08\u4f8b\u5982\uff0c\u6ce8\u518c\u8868\u548c\u76ee\u5f55\u670d\u52a1\uff09\u53ef\u4ee5\u901a\u8fc7\u517c\u5bb9\u5305\u542f\u7528\uff0c\u4f7f\u8fd9\u4e9b API \u5728 .NET 5+ \u4e2d\u53ef\u7528\u3002\u5b83\u4eec\u4ec5\u5728 Windows \u4e2d\u8fd0\u884c .NET 5+ \u65f6\u53ef\u7528\uff0c\u800c\u4e0d\u662f\u5728 Linux \u6216 macOS \u4e2d\u8fd0\u884c\uff0c\u56e0\u6b64\u60a8\u9700\u8981\u6ce8\u610f\u6b64\u7c7b\u5e94\u7528\u7a0b\u5e8f\u4ec5\u5728 Windows \u73af\u5883\u4e2d\u8fd0\u884c\uff0c\u6216\u8005\u8003\u8651\u53ef\u80fd\u7f3a\u5c11\u7684 API\u3002<\/p>\n<p><strong>TIP<\/strong> The Windows Compatibility Pack is designed to help port code from .NET Framework to .NET Core\/.NET 5+. See <a href=\"http:\/\/mng.bz\/2DeX\">http:\/\/mng.bz\/2DeX<\/a>.<\/p>\n<p><strong>\u63d0\u793a<\/strong> Windows \u517c\u5bb9\u5305\u65e8\u5728\u5e2e\u52a9\u5c06\u4ee3\u7801\u4ece .NET Framework \u79fb\u690d\u5230 .NET Core\/.NET 5+\u3002\u8bf7\u53c2\u9605 <a href=\"http:\/\/mng.bz\/2DeX\">http:\/\/mng.bz\/2DeX<\/a>\u3002<\/p>\n<p>The hosting model for the previous ASP.NET framework was a relatively complex one, relying on Windows IIS to provide the web-server hosting. In a cross-platform environment, this kind of symbiotic relationship isn\u2019t possible, so an alternative hosting model has been adopted\u2014one that separates web applications from the underlying host. This opportunity has led to the development of Kestrel, a fast, cross-platform HTTP server on which ASP.NET Core can run.<\/p>\n<p>\u4ee5\u524d\u7684 ASP.NET \u6846\u67b6\u7684\u6258\u7ba1\u6a21\u578b\u76f8\u5bf9\u590d\u6742\uff0c\u4f9d\u8d56 Windows IIS \u63d0\u4f9b Web \u670d\u52a1\u5668\u6258\u7ba1\u3002\u5728\u8de8\u5e73\u53f0\u73af\u5883\u4e2d\uff0c\u8fd9\u79cd\u5171\u751f\u5173\u7cfb\u662f\u4e0d\u53ef\u80fd\u7684\uff0c\u56e0\u6b64\u91c7\u7528\u4e86\u53e6\u4e00\u79cd\u6258\u7ba1\u6a21\u578b\uff0c\u5373\u5c06 Web \u5e94\u7528\u7a0b\u5e8f\u4e0e\u5e95\u5c42\u4e3b\u673a\u5206\u5f00\u7684\u6a21\u578b\u3002\u8fd9\u4e2a\u673a\u4f1a\u5bfc\u81f4\u4e86 Kestrel \u7684\u5f00\u53d1\uff0c\u8fd9\u662f\u4e00\u79cd\u5feb\u901f\u3001\u8de8\u5e73\u53f0\u7684 HTTP \u670d\u52a1\u5668\uff0cASP.NET Core \u53ef\u4ee5\u5728\u8be5\u670d\u52a1\u5668\u4e0a\u8fd0\u884c\u3002<\/p>\n<p>Instead of the previous design, whereby IIS calls into speci\ufb01c points of your application, ASP.NET Core applications are console applications that self-host a web server and handle requests directly, as shown in \ufb01gure 2.6. This hosting model is conceptually much simpler and allows you to test and debug your applications from the command line, though it doesn\u2019t necessarily remove the need to run IIS (or the equivalent) in production.<\/p>\n<p>\u4e0e\u4ee5\u524d\u7684\u8bbe\u8ba1\u4e0d\u540c\uff0cIIS \u8c03\u7528\u5e94\u7528\u7a0b\u5e8f\u7684\u7279\u5b9a\u70b9\uff0cASP.NET Core \u5e94\u7528\u7a0b\u5e8f\u662f\u81ea\u6258\u7ba1 Web \u670d\u52a1\u5668\u5e76\u76f4\u63a5\u5904\u7406\u8bf7\u6c42\u7684\u63a7\u5236\u53f0\u5e94\u7528\u7a0b\u5e8f\uff0c\u5982\u56fe 2.6 \u6240\u793a\u3002\u6b64\u6258\u7ba1\u6a21\u578b\u5728\u6982\u5ff5\u4e0a\u8981\u7b80\u5355\u5f97\u591a\uff0c\u5e76\u4e14\u5141\u8bb8\u60a8\u4ece\u547d\u4ee4\u884c\u6d4b\u8bd5\u548c\u8c03\u8bd5\u5e94\u7528\u7a0b\u5e8f\uff0c\u5c3d\u7ba1\u5b83\u4e0d\u4e00\u5b9a\u6d88\u9664\u5728\u751f\u4ea7\u4e2d\u8fd0\u884c IIS\uff08\u6216\u7b49\u6548\u9879\uff09\u7684\u9700\u8981\u3002<\/p>\n<blockquote>\n<p>ASP.NET Core and reverse proxies<br \/>\nASP.NET Core \u548c\u53cd\u5411\u4ee3\u7406<br \/>\nYou can expose ASP.NET Core applications directly to the internet so that Kestrel receives requests directly from the network. That approach is fully supported. It\u2019s more common, however, to use a reverse proxy between the raw network and your application. In Windows, the reverse-proxy server typically is IIS; in Linux or macOS, it might be NGINX, HAProxy, or Apache.There\u2019s even an ASP.NET Core-based reverse proxy library called YARP (<a href=\"https:\/\/microsoft.github.io\/reverse-proxy\">https:\/\/microsoft.github.io\/reverse-proxy<\/a>) that you can use to build your own reverse proxy.<br \/>\n\u60a8\u53ef\u4ee5\u5c06 ASP.NET Core \u5e94\u7528\u7a0b\u5e8f\u76f4\u63a5\u516c\u5f00\u5230 Internet\uff0c\u4ee5\u4fbf Kestrel \u76f4\u63a5\u4ece\u7f51\u7edc\u63a5\u6536\u8bf7\u6c42\u3002\u8fd9\u79cd\u65b9\u6cd5\u5b8c\u5168\u53d7\u652f\u6301\u3002\u4f46\u662f\uff0c\u66f4\u5e38\u89c1\u7684\u662f\u5728\u539f\u59cb\u7f51\u7edc\u548c\u5e94\u7528\u7a0b\u5e8f\u4e4b\u95f4\u4f7f\u7528\u53cd\u5411\u4ee3\u7406\u3002\u5728 Windows \u4e2d\uff0c\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668\u901a\u5e38\u662f IIS;\u5728 Linux \u6216 macOS \u4e2d\uff0c\u5b83\u53ef\u80fd\u662f NGINX\u3001HAProxy \u6216 Apache\u3002\u751a\u81f3\u8fd8\u6709\u4e00\u4e2a\u540d\u4e3a YARP \uff08<a href=\"https:\/\/microsoft.github.io\/reverse-proxy\">https:\/\/microsoft.github.io\/reverse-proxy<\/a>\uff09 \u7684\u57fa\u4e8e ASP.NET Core \u7684\u53cd\u5411\u4ee3\u7406\u5e93\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u6784\u5efa\u81ea\u5df1\u7684\u53cd\u5411\u4ee3\u7406\u3002<br \/>\nA reverse proxy is software responsible for receiving requests and forwarding them to the appropriate web server. The reverse proxy is exposed directly to the internet, whereas the underlying web server is exposed only to the proxy. This setup has several bene\ufb01ts, primarily security and performance for the web servers.<br \/>\n\u53cd\u5411\u4ee3\u7406\u662f\u8d1f\u8d23\u63a5\u6536\u8bf7\u6c42\u5e76\u5c06\u5176\u8f6c\u53d1\u5230\u9002\u5f53\u7684 Web \u670d\u52a1\u5668\u7684\u8f6f\u4ef6\u3002\u53cd\u5411\u4ee3\u7406\u76f4\u63a5\u5411 Internet \u516c\u5f00\uff0c\u800c\u5e95\u5c42 Web \u670d\u52a1\u5668\u4ec5\u5411\u4ee3\u7406\u516c\u5f00\u3002\u6b64\u8bbe\u7f6e\u6709\u51e0\u4e2a\u597d\u5904\uff0c\u4e3b\u8981\u662f Web \u670d\u52a1\u5668\u7684\u5b89\u5168\u6027\u548c\u6027\u80fd\u3002<br \/>\nYou may think that having a reverse proxy and a web server is somewhat redundant. Why not have one or the other? Well, one bene\ufb01t is the decoupling of your application from the underlying operating system. The same ASP.NET Core web server, Kestrel, can be cross-platform and used behind a variety of proxies without putting any constraints on a particular implementation. Alternatively, if you wrote a new ASP.NET Core web server, you could use it in place of Kestrel without needing to change anything else about your application.<br \/>\n\u60a8\u53ef\u80fd\u8ba4\u4e3a\u62e5\u6709\u53cd\u5411\u4ee3\u7406\u548c Web \u670d\u52a1\u5668\u6709\u70b9\u591a\u4f59\u3002\u4e3a\u4ec0\u4e48\u4e0d\u62e5\u6709\u4e00\u4e2a\u6216\u53e6\u4e00\u4e2a\u5462\uff1f\u55ef\uff0c\u4e00\u4e2a\u597d\u5904\u662f\u5c06\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u4e0e\u5e95\u5c42\u4f5c\u7cfb\u7edf\u89e3\u8026\u3002\u76f8\u540c\u7684 ASP.NET Core Web \u670d\u52a1\u5668 Kestrel \u53ef\u4ee5\u662f\u8de8\u5e73\u53f0\u7684\uff0c\u5e76\u5728\u5404\u79cd\u4ee3\u7406\u540e\u9762\u4f7f\u7528\uff0c\u800c\u4e0d\u4f1a\u5bf9\u7279\u5b9a\u5b9e\u73b0\u65bd\u52a0\u4efb\u4f55\u9650\u5236\u3002\u6216\u8005\uff0c\u5982\u679c\u60a8\u7f16\u5199\u4e86\u4e00\u4e2a\u65b0\u7684 ASP.NET Core Web \u670d\u52a1\u5668\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u4ee3\u66ff Kestrel\uff0c\u800c\u65e0\u9700\u66f4\u6539\u6709\u5173\u5e94\u7528\u7a0b\u5e8f\u7684\u4efb\u4f55\u5176\u4ed6\u5185\u5bb9\u3002<br \/>\nAnother bene\ufb01t of a reverse proxy is that it can be hardened against potential threats from the public internet. Reverse proxies are often responsible for additional aspects, such as restarting a process that has crashed. Kestrel can remain a simple HTTP server, not having to worry about these extra features, when it\u2019s used behind a reverse proxy. You can think of this approach as being a simple separation of concerns: Kestrel is concerned with generating HTTP responses, whereas the reverse proxy is concerned with handling the connection to the internet.<br \/>\n\u53cd\u5411\u4ee3\u7406\u7684\u53e6\u4e00\u4e2a\u597d\u5904\u662f\u5b83\u53ef\u4ee5\u9488\u5bf9\u6765\u81ea\u516c\u5171\u4e92\u8054\u7f51\u7684\u6f5c\u5728\u5a01\u80c1\u8fdb\u884c\u5f3a\u5316\u3002\u53cd\u5411\u4ee3\u7406\u901a\u5e38\u8d1f\u8d23\u5176\u4ed6\u65b9\u9762\uff0c\u4f8b\u5982\u91cd\u65b0\u542f\u52a8\u5df2\u5d29\u6e83\u7684\u8fdb\u7a0b\u3002Kestrel \u53ef\u4ee5\u4fdd\u6301\u4e00\u4e2a\u7b80\u5355\u7684 HTTP \u670d\u52a1\u5668\uff0c\u5f53\u5b83\u5728\u53cd\u5411\u4ee3\u7406\u540e\u9762\u4f7f\u7528\u65f6\uff0c\u4e0d\u5fc5\u62c5\u5fc3\u8fd9\u4e9b\u989d\u5916\u7684\u529f\u80fd\u3002\u60a8\u53ef\u4ee5\u5c06\u6b64\u65b9\u6cd5\u89c6\u4e3a\u7b80\u5355\u7684\u5173\u6ce8\u70b9\u5206\u79bb\uff1aKestrel \u5173\u6ce8\u751f\u6210 HTTP \u54cd\u5e94\uff0c\u800c\u53cd\u5411\u4ee3\u7406\u5173\u6ce8\u5904\u7406\u4e0e Internet \u7684\u8fde\u63a5\u3002<\/p>\n<\/blockquote>\n<p><img decoding=\"async\" src=\"\/images\/aspnetcoreinaction\/0206.png\" alt=\"alt text\" \/><\/p>\n<p>Figure 2.6 The di\ufb00erence between hosting models in ASP.NET (top) and ASP.NET Core (bottom). In the previous version of ASP.NET, IIS is tightly coupled with the application. The hosting model in ASP.NET Core is simpler; IIS hands o\ufb00 the request to a self-hosted web server in the ASP.NET Core application and receives the response but has no deeper knowledge of the application.<\/p>\n<p>\u56fe 2.6 \u5728 ASP.NET\uff08\u4e0a\uff09\u548c ASP.NET Core \u4e2d\u6258\u7ba1\u6a21\u578b\uff08\u4e0b\uff09\u4e4b\u95f4\u7684\u533a\u522b\u3002\u5728\u65e9\u671f\u7248\u672c\u7684 ASP.NET \u4e2d\uff0cIIS \u4e0e\u5e94\u7528\u7a0b\u5e8f\u7d27\u5bc6\u8026\u5408\u3002ASP.NET Core \u4e2d\u7684\u6258\u7ba1\u6a21\u578b\u66f4\u7b80\u5355;IIS \u5c06\u8bf7\u6c42\u79fb\u4ea4\u7ed9 ASP.NET Core \u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u81ea\u6258\u7ba1 Web \u670d\u52a1\u5668\u5e76\u63a5\u6536\u54cd\u5e94\uff0c\u4f46\u5bf9\u5e94\u7528\u7a0b\u5e8f\u6ca1\u6709\u66f4\u6df1\u5165\u7684\u4e86\u89e3\u3002<\/p>\n<p><strong>NOTE<\/strong> By default, when running in Windows, ASP.NET Core runs inside IIS, as shown in \ufb01gure 2.6, which can provide better performance than the reverse-proxy version. This is primarily a deployment detail and doesn\u2019t change the way you build ASP.NET Core applications.<\/p>\n<p><strong>\u6ce8\u610f<\/strong> \u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5728 Windows \u4e2d\u8fd0\u884c\u65f6\uff0cASP.NET Core \u5728 IIS \u4e2d\u8fd0\u884c\uff0c\u5982\u56fe 2.6 \u6240\u793a\uff0c\u5b83\u53ef\u4ee5\u63d0\u4f9b\u6bd4\u53cd\u5411\u4ee3\u7406\u7248\u672c\u66f4\u597d\u7684\u6027\u80fd\u3002\u8fd9\u4e3b\u8981\u662f\u90e8\u7f72\u8be6\u7ec6\u4fe1\u606f\uff0c\u4e0d\u4f1a\u6539\u53d8\u60a8\u6784\u5efa ASP.NET Core \u5e94\u7528\u7a0b\u5e8f\u7684\u65b9\u5f0f\u3002<\/p>\n<p>Changing the hosting model to use a built-in HTTP web server has created another opportunity. Performance has been something of a sore point for ASP.NET applications in the past. It\u2019s certainly possible to build high-performing applications\u2014Stack Over\ufb02ow (<a href=\"https:\/\/stackover\ufb02ow.com\">https:\/\/stackover\ufb02ow.com<\/a>) is a testament to that fact\u2014but the web framework itself isn\u2019t designed with performance as a priority, so it can end up being an obstacle.<\/p>\n<p>\u5c06\u6258\u7ba1\u6a21\u578b\u66f4\u6539\u4e3a\u4f7f\u7528\u5185\u7f6e HTTP Web \u670d\u52a1\u5668\u521b\u9020\u4e86\u53e6\u4e00\u4e2a\u673a\u4f1a\u3002\u8fc7\u53bb\uff0c\u6027\u80fd\u4e00\u76f4\u662f ASP.NET \u5e94\u7528\u7a0b\u5e8f\u7684\u75db\u70b9\u3002\u6784\u5efa\u9ad8\u6027\u80fd\u5e94\u7528\u7a0b\u5e8f\u5f53\u7136\u662f\u53ef\u80fd\u7684 \u2014 Stack Overflow \uff08<a href=\"https:\/\/stackoverflow.com\">https:\/\/stackoverflow.com<\/a>\uff09 \u8bc1\u660e\u4e86\u8fd9\u4e00\u4e8b\u5b9e \u2014 \u4f46 Web \u6846\u67b6\u672c\u8eab\u5728\u8bbe\u8ba1\u65f6\u5e76\u672a\u5c06\u6027\u80fd\u4f5c\u4e3a\u4f18\u5148\u4e8b\u9879\uff0c\u56e0\u6b64\u5b83\u6700\u7ec8\u53ef\u80fd\u4f1a\u6210\u4e3a\u4e00\u4e2a\u969c\u788d\u3002<\/p>\n<p>To make the product competitive cross-platform, the ASP.NET team focused on making the Kestrel HTTP server as fast as possible. TechEmpower (<a href=\"https:\/\/www.techempower.com\/benchmarks\">https:\/\/www.techempower.com\/benchmarks<\/a>) has been running benchmarks on a wide range of web frameworks from various languages for several years now. In round 20 of the plain-text benchmarks, TechEmpower announced that ASP.NET Core with Kestrel was among the 10 fastest of more than 400 frameworks tested!3<\/p>\n<p>\u4e3a\u4e86\u4f7f\u4ea7\u54c1\u5728\u8de8\u5e73\u53f0\u65b9\u9762\u5177\u6709\u7ade\u4e89\u529b\uff0cASP.NET \u56e2\u961f\u4e13\u6ce8\u4e8e\u4f7f Kestrel HTTP \u670d\u52a1\u5668\u5c3d\u53ef\u80fd\u5feb\u3002TechEmpower \uff08<a href=\"https:\/\/www.techempower.com\/benchmarks\">https:\/\/www.techempower.com\/benchmarks<\/a>\uff09 \u591a\u5e74\u6765\u4e00\u76f4\u5728\u5404\u79cd\u8bed\u8a00\u7684\u5404\u79cd Web \u6846\u67b6\u4e0a\u8fd0\u884c\u57fa\u51c6\u6d4b\u8bd5\u3002\u5728\u7b2c 20 \u8f6e\u7eaf\u6587\u672c\u57fa\u51c6\u6d4b\u8bd5\u4e2d\uff0cTechEmpower \u5ba3\u5e03 ASP.NET Core with Kestrel \u662f\u6d4b\u8bd5\u7684 400 \u591a\u4e2a\u6846\u67b6\u4e2d\u6700\u5feb\u7684 10 \u4e2a\u6846\u67b6\u4e4b\u4e00\uff013<\/p>\n<blockquote>\n<p>Web servers: Naming things is hard<br \/>\nWeb \u670d\u52a1\u5668\uff1a\u547d\u540d\u5f88\u56f0\u96be<br \/>\nOne di\ufb03cult aspect of programming for the web is the confusing array of often-con\ufb02icting terminology. If you\u2019ve used IIS, for example, you may have described it as a web server or possibly a web host. Conversely, if you\u2019ve ever built an application with Node.js, you may have also referred to that application as a web server. Or you may have called the physical machine on which your application runs a web server. Similarly, you may have built an application for the internet and called it a website or a web application, probably somewhat arbitrarily based on the level of dynamism it displayed.<br \/>\nWeb \u7f16\u7a0b\u7684\u4e00\u4e2a\u56f0\u96be\u65b9\u9762\u662f\u4e00\u7cfb\u5217\u7ecf\u5e38\u76f8\u4e92\u51b2\u7a81\u7684\u4ee4\u4eba\u56f0\u60d1\u7684\u672f\u8bed\u3002\u4f8b\u5982\uff0c\u5982\u679c\u60a8\u4f7f\u7528\u8fc7 IIS\uff0c\u60a8\u53ef\u80fd\u5df2\u5c06\u5176\u63cf\u8ff0\u4e3a Web \u670d\u52a1\u5668\u6216\u53ef\u80fd\u662f Web \u4e3b\u673a\u3002\u76f8\u53cd\uff0c\u5982\u679c\u60a8\u66fe\u7ecf\u4f7f\u7528 Node.js \u6784\u5efa\u8fc7\u5e94\u7528\u7a0b\u5e8f\uff0c\u60a8\u53ef\u80fd\u4e5f\u66fe\u5c06\u8be5\u5e94\u7528\u7a0b\u5e8f\u79f0\u4e3a Web \u670d\u52a1\u5668\u3002\u6216\u8005\uff0c\u60a8\u53ef\u80fd\u5df2\u5c06\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u7684\u7269\u7406\u8ba1\u7b97\u673a\u79f0\u4e3a Web \u670d\u52a1\u5668\u3002\u540c\u6837\uff0c\u60a8\u53ef\u80fd\u5df2\u7ecf\u6784\u5efa\u4e86\u4e00\u4e2a\u7528\u4e8e Internet \u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u5c06\u5176\u79f0\u4e3a\u7f51\u7ad9\u6216 Web \u5e94\u7528\u7a0b\u5e8f\uff0c\u53ef\u80fd\u6839\u636e\u5b83\u663e\u793a\u7684\u52a8\u6001\u6c34\u5e73\u6709\u70b9\u6b66\u65ad\u3002<br \/>\nIn this book, when I say web server in the context of ASP.NET Core, I\u2019m referring to the HTTP server that runs as part of your ASP.NET Core application. By default, this server is the Kestrel web server, but that\u2019s not a requirement. It\u2019s possible to write a replacement web server for Kestrel if you so desire.<br \/>\n\u5728\u672c\u4e66\u4e2d\uff0c\u5f53\u6211\u5728 ASP.NET Core \u7684\u4e0a\u4e0b\u6587\u4e2d\u63d0\u5230 Web \u670d\u52a1\u5668\u65f6\uff0c\u6211\u6307\u7684\u662f\u4f5c\u4e3a ASP.NET Core \u5e94\u7528\u7a0b\u5e8f\u7684\u4e00\u90e8\u5206\u8fd0\u884c\u7684 HTTP \u670d\u52a1\u5668\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6b64\u670d\u52a1\u5668\u662f Kestrel Web \u670d\u52a1\u5668\uff0c\u4f46\u8fd9\u4e0d\u662f\u5fc5\u9700\u7684\u3002\u5982\u679c\u60a8\u613f\u610f\uff0c\u53ef\u4ee5\u4e3a Kestrel \u7f16\u5199\u66ff\u6362 Web \u670d\u52a1\u5668\u3002<br \/>\nThe web server is responsible for receiving HTTP requests and generating responses. In the previous version of ASP.NET, IIS took this role, but in ASP.NET Core, Kestrel is the web server.<br \/>\nWeb \u670d\u52a1\u5668\u8d1f\u8d23\u63a5\u6536 HTTP \u8bf7\u6c42\u5e76\u751f\u6210\u54cd\u5e94\u3002\u5728\u65e9\u671f\u7248\u672c\u7684 ASP.NET \u4e2d\uff0cIIS \u627f\u62c5\u4e86\u6b64\u89d2\u8272\uff0c\u4f46\u5728 ASP.NET Core \u4e2d\uff0cKestrel \u662f Web \u670d\u52a1\u5668\u3002<br \/>\nI\u2019ll use the term web application in this book to describe ASP.NET Core applications, regardless of whether they contain only static content or are dynamic. Either way, these applications are accessed via the web, so that name seems to be the most appropriate.<br \/>\n\u5728\u672c\u4e66\u4e2d\uff0c\u6211\u5c06\u4f7f\u7528\u672f\u8bed Web \u5e94\u7528\u7a0b\u5e8f\u6765\u63cf\u8ff0 ASP.NET Core \u5e94\u7528\u7a0b\u5e8f\uff0c\u65e0\u8bba\u5b83\u4eec\u53ea\u5305\u542b\u9759\u6001\u5185\u5bb9\u8fd8\u662f\u52a8\u6001\u7684\u3002\u65e0\u8bba\u54ea\u79cd\u65b9\u5f0f\uff0c\u8fd9\u4e9b\u5e94\u7528\u7a0b\u5e8f\u90fd\u662f\u901a\u8fc7 Web \u8bbf\u95ee\u7684\uff0c\u56e0\u6b64\u8be5\u540d\u79f0\u4f3c\u4e4e\u662f\u6700\u5408\u9002\u7684\u3002<\/p>\n<\/blockquote>\n<p>Many of the performance improvements made to Kestrel came not from the ASP.NET team members themselves, but from contributors to the open-source project on GitHub (<a href=\"https:\/\/github.com\/dotnet\/aspnetcore\">https:\/\/github.com\/dotnet\/aspnetcore<\/a>). Developing in the open means that you typically see \ufb01xes and features make their way to production faster than you would for the previous version of ASP.NET, which was dependent on .NET Framework and Windows and, as such, had long release cycles.<\/p>\n<p>\u5bf9 Kestrel \u6240\u505a\u7684\u8bb8\u591a\u6027\u80fd\u6539\u8fdb\u5e76\u975e\u6765\u81ea ASP.NET \u56e2\u961f\u6210\u5458\u672c\u8eab\uff0c\u800c\u662f\u6765\u81ea GitHub \uff08<a href=\"https:\/\/github.com\/dotnet\/aspnetcore\">https:\/\/github.com\/dotnet\/aspnetcore<\/a>\uff09 \u4e0a\u5f00\u6e90\u9879\u76ee\u7684\u8d21\u732e\u8005\u3002\u4ee5\u5f00\u653e\u65b9\u5f0f\u8fdb\u884c\u5f00\u53d1\u610f\u5473\u7740\u60a8\u901a\u5e38\u4f1a\u770b\u5230\u4fee\u590d\u7a0b\u5e8f\u548c\u529f\u80fd\u6bd4\u4ee5\u524d\u7248\u672c\u7684 ASP.NET \u66f4\u5feb\u5730\u8fdb\u5165\u751f\u4ea7\u73af\u5883\uff0c\u8be5\u7248\u672c\u4f9d\u8d56\u4e8e .NET Framework \u548c Windows\uff0c\u56e0\u6b64\u5177\u6709\u8f83\u957f\u7684\u53d1\u5e03\u5468\u671f\u3002<\/p>\n<p>By contrast, .NET 5+ and hence ASP.NET Core are designed to be released in small increments. Major versions will be released on a predictable cadence, with a new version every year and a new LTS version released every two years (<a href=\"http:\/\/mng.bz\/1qrg\">http:\/\/mng.bz\/1qrg<\/a>). In addition, bug \ufb01xes and minor updates can be released as and when they\u2019re needed.Additional functionality is provided in NuGet packages independent of the underlying .NET 5+ platform.<br \/>\n\u76f8\u6bd4\u4e4b\u4e0b\uff0c.NET 5+ \u548c ASP.NET Core \u65e8\u5728\u4ee5\u5c0f\u589e\u91cf\u53d1\u5e03\u3002\u4e3b\u8981\u7248\u672c\u5c06\u4ee5\u53ef\u9884\u6d4b\u7684\u8282\u594f\u53d1\u5e03\uff0c\u6bcf\u5e74\u53d1\u5e03\u4e00\u4e2a\u65b0\u7248\u672c\uff0c\u6bcf\u4e24\u5e74 \uff08<a href=\"http:\/\/mng.bz\/1qrg\">http:\/\/mng.bz\/1qrg<\/a>\uff09 \u53d1\u5e03\u4e00\u4e2a\u65b0\u7684 LTS \u7248\u672c\u3002\u6b64\u5916\uff0c\u53ef\u4ee5\u5728\u9700\u8981\u65f6\u53d1\u5e03\u9519\u8bef\u4fee\u590d\u548c\u6b21\u8981\u66f4\u65b0\u3002NuGet \u5305\u4e2d\u63d0\u4f9b\u4e86\u72ec\u7acb\u4e8e\u57fa\u7840 .NET 5+ \u5e73\u53f0\u7684\u5176\u4ed6\u529f\u80fd\u3002<\/p>\n<p><strong>NOTE<\/strong> NuGet is a package manager for .NET that enables you to import libraries into your projects. It\u2019s equivalent to Ruby Gems, npm for JavaScript, or Maven for Java.<\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong> NuGet \u662f .NET \u7684\u5305\u7ba1\u7406\u5668\uff0c\u53ef\u7528\u4e8e\u5c06\u5e93\u5bfc\u5165\u5230\u9879\u76ee\u4e2d\u3002\u5b83\u7b49\u6548\u4e8e Ruby Gems\u3001\u7528\u4e8e JavaScript \u7684 npm \u6216\u7528\u4e8e Java \u7684 Maven\u3002<\/p>\n<p>To enable this approach to releases, ASP.NET Core is highly modular, with as little coupling to other features as possible. This modularity lends itself to a pay-for-play approach to dependencies, where you start with a bare-bones application and add only the libraries you require, as opposed to the kitchen-sink approach of previous ASP.NET applications. Even MVC is an optional package! But don\u2019t worry\u2014this approach doesn\u2019t mean that ASP.NET Core is lacking in features, only that you need to opt into them. Some of the key infrastructure improvements include<\/p>\n<p>\u4e3a\u4e86\u5b9e\u73b0\u8fd9\u79cd\u53d1\u5e03\u65b9\u6cd5\uff0cASP.NET Core \u662f\u9ad8\u5ea6\u6a21\u5757\u5316\u7684\uff0c\u5c3d\u53ef\u80fd\u5c11\u5730\u4e0e\u5176\u4ed6\u529f\u80fd\u8026\u5408\u3002\u8fd9\u79cd\u6a21\u5757\u5316\u6027\u9002\u7528\u4e8e\u4f9d\u8d56\u9879\u7684\u4ed8\u8d39\u65b9\u6cd5\uff0c\u5728\u8fd9\u79cd\u65b9\u6cd5\u4e2d\uff0c\u60a8\u4ece\u4e00\u4e2a\u57fa\u672c\u7684\u5e94\u7528\u7a0b\u5e8f\u5f00\u59cb\uff0c\u53ea\u6dfb\u52a0\u60a8\u9700\u8981\u7684\u5e93\uff0c\u800c\u4e0d\u662f\u4ee5\u524d\u7684 ASP.NET \u5e94\u7528\u7a0b\u5e8f\u7684\u53a8\u623f\u63a5\u6536\u5668\u65b9\u6cd5\u3002\u751a\u81f3 MVC \u4e5f\u662f\u4e00\u4e2a\u53ef\u9009\u5305\uff01\u4f46\u522b\u62c5\u5fc3\uff0c\u8fd9\u79cd\u65b9\u6cd5\u5e76\u4e0d\u610f\u5473\u7740 ASP.NET Core \u7f3a\u5c11\u529f\u80fd\uff0c\u53ea\u662f\u60a8\u9700\u8981\u9009\u62e9\u4f7f\u7528\u8fd9\u4e9b\u529f\u80fd\u3002\u4e00\u4e9b\u5173\u952e\u7684\u57fa\u7840\u8bbe\u65bd\u6539\u8fdb\u5305\u62ec<\/p>\n<ul>\n<li>\n<p>Middleware pipeline for de\ufb01ning your application\u2019s behavior<br \/>\n\u7528\u4e8e\u5b9a\u4e49\u5e94\u7528\u7a0b\u5e8f\u884c\u4e3a\u7684\u4e2d\u95f4\u4ef6\u7ba1\u9053<\/p>\n<\/li>\n<li>\n<p>Built-in support for dependency injection<br \/>\n\u5bf9\u4f9d\u8d56\u9879\u6ce8\u5165\u7684\u5185\u7f6e\u652f\u6301<\/p>\n<\/li>\n<li>\n<p>Combined UI (MVC) and API (web API) infrastructure<br \/>\n\u7ec4\u5408\u7684 UI \uff08MVC\uff09 \u548c API \uff08Web API\uff09 \u57fa\u7840\u8bbe\u65bd<\/p>\n<\/li>\n<li>\n<p>Highly extensible con\ufb01guration system Standardized, extensible logging system<br \/>\n\u9ad8\u5ea6\u53ef\u6269\u5c55\u7684\u914d\u7f6e\u7cfb\u7edf \u6807\u51c6\u5316\u3001\u53ef\u6269\u5c55\u7684\u65e5\u5fd7\u8bb0\u5f55\u7cfb\u7edf<\/p>\n<\/li>\n<li>\n<p>Uses asynchronous programming by default for<br \/>\n\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u4f7f\u7528\u5f02\u6b65\u7f16\u7a0b<\/p>\n<\/li>\n<li>\n<p>built-in scalability on cloud platforms<br \/>\n\u4e91\u5e73\u53f0\u4e0a\u7684\u5185\u7f6e\u53ef\u6269\u5c55\u6027<\/p>\n<\/li>\n<\/ul>\n<p>Each of these features was possible in the previous version of ASP.NET but required a fair amount of additional work to set up. With ASP.NET Core, they\u2019re all there, ready and waiting to be connected.<br \/>\n\u8fd9\u4e9b\u529f\u80fd\u5728\u4ee5\u524d\u7684 ASP.NET \u7248\u672c\u4e2d\u90fd\u662f\u53ef\u80fd\u7684\uff0c\u4f46\u9700\u8981\u76f8\u5f53\u591a\u7684\u989d\u5916\u5de5\u4f5c\u624d\u80fd\u5efa\u7acb\u3002\u6709\u4e86 ASP.NET Core\uff0c\u5b83\u4eec\u90fd\u5df2\u51c6\u5907\u5c31\u7eea\uff0c\u7b49\u5f85\u8fde\u63a5\u3002<\/p>\n<p>Microsoft fully supports ASP.NET Core, so if you want to build a new system, there\u2019s no signi\ufb01cant reason not to use it. The largest obstacle you\u2019re likely to come across is wanting to use programming models that are no longer supported in ASP.NET Core, such as Web Forms or WCF Server, as I\u2019ll discuss in the next section.<\/p>\n<p>Microsoft \u5b8c\u5168\u652f\u6301 ASP.NET Core\uff0c\u56e0\u6b64\u5982\u679c\u60a8\u60f3\u6784\u5efa\u4e00\u4e2a\u65b0\u7cfb\u7edf\uff0c\u6ca1\u6709\u660e\u663e\u7684\u7406\u7531\u4e0d\u4f7f\u7528\u5b83\u3002\u60a8\u53ef\u80fd\u9047\u5230\u7684\u6700\u5927\u969c\u788d\u662f\u5e0c\u671b\u4f7f\u7528 ASP.NET Core \u4e2d\u4e0d\u518d\u652f\u6301\u7684\u7f16\u7a0b\u6a21\u578b\uff0c\u4f8b\u5982 Web \u7a97\u4f53\u6216 WCF Server\uff0c\u6211\u5c06\u5728\u4e0b\u4e00\u8282\u4e2d\u8ba8\u8bba\u3002<\/p>\n<p>I hope that this section whetted your appetite to use ASP.NET Core for building new applications. But if you\u2019re an existing ASP.NET developer considering whether to convert an existing ASP.NET application to ASP.NET Core, that\u2019s another question entirely.<\/p>\n<p>\u6211\u5e0c\u671b\u672c\u8282\u80fd\u6fc0\u53d1\u60a8\u4f7f\u7528 ASP.NET Core \u6784\u5efa\u65b0\u5e94\u7528\u7a0b\u5e8f\u7684\u5174\u8da3\u3002\u4f46\u662f\uff0c\u5982\u679c\u4f60\u662f\u73b0\u6709\u7684 ASP.NET \u5f00\u53d1\u4eba\u5458\uff0c\u6b63\u5728\u8003\u8651\u662f\u5426\u5c06\u73b0\u6709\u7684 ASP.NET \u5e94\u7528\u7a0b\u5e8f\u8f6c\u6362\u4e3a ASP.NET Core\uff0c\u90a3\u5b8c\u5168\u662f\u53e6\u4e00\u4e2a\u95ee\u9898\u3002<\/p>\n<h4>2.4.3 Converting an existing ASP.NET application to ASP.NET Core\u200c<\/h4>\n<h4>2.4.3 \u5c06\u73b0\u6709 ASP.NET \u5e94\u7528\u7a0b\u5e8f\u8f6c\u6362\u4e3a ASP.NET Core<\/h4>\n<p>By contrast with new applications, an existing application presumably already provides value, so there should always be a tangible bene\ufb01t to performing what may amount to a signi\ufb01cant rewrite in converting from ASP.NET to ASP.NET Core. The advantages of adopting ASP.NET Core are much the same as those for new applications: cross-platform deployment, modular features, and a focus on performance. Whether the bene\ufb01ts are su\ufb03cient will depend largely on the particulars of your application, but some characteristics make conversion more di\ufb03cult:<\/p>\n<p>\u4e0e\u65b0\u5e94\u7528\u7a0b\u5e8f\u76f8\u6bd4\uff0c\u73b0\u6709\u5e94\u7528\u7a0b\u5e8f\u53ef\u80fd\u5df2\u7ecf\u63d0\u4f9b\u4e86\u4ef7\u503c\uff0c\u56e0\u6b64\u5728\u4ece ASP.NET \u8f6c\u6362\u4e3a ASP.NET Core \u7684\u8fc7\u7a0b\u4e2d\u6267\u884c\u53ef\u80fd\u76f8\u5f53\u4e8e\u91cd\u5927\u91cd\u5199\u7684\u4f5c\u5e94\u8be5\u59cb\u7ec8\u4f1a\u5e26\u6765\u5207\u5b9e\u7684\u597d\u5904\u3002\u91c7\u7528 ASP.NET Core \u7684\u4f18\u52bf\u4e0e\u65b0\u5e94\u7528\u7a0b\u5e8f\u7684\u4f18\u52bf\u5927\u81f4\u76f8\u540c\uff1a\u8de8\u5e73\u53f0\u90e8\u7f72\u3001\u6a21\u5757\u5316\u529f\u80fd\u548c\u5bf9\u6027\u80fd\u7684\u5173\u6ce8\u3002\u597d\u5904\u662f\u5426\u8db3\u591f\u5728\u5f88\u5927\u7a0b\u5ea6\u4e0a\u53d6\u51b3\u4e8e\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u7684\u5177\u4f53\u60c5\u51b5\uff0c\u4f46\u6709\u4e9b\u7279\u5f81\u4f7f\u8f6c\u6362\u66f4\u52a0\u56f0\u96be\uff1a<\/p>\n<ul>\n<li>\n<p>Your application uses ASP.NET Web Forms.<br \/>\n\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u4f7f\u7528 ASP.NET Web Forms\u3002<\/p>\n<\/li>\n<li>\n<p>Your application is built with WCF.<br \/>\n\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u662f\u4f7f\u7528 WCF \u6784\u5efa\u7684\u3002<\/p>\n<\/li>\n<li>\n<p>Your application is large, with many advanced MVC features.<br \/>\n\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u5f88\u5927\uff0c\u5177\u6709\u8bb8\u591a\u9ad8\u7ea7 MVC \u529f\u80fd\u3002<\/p>\n<\/li>\n<\/ul>\n<p>If you have an ASP.NET Web Forms application, attempting to convert it directly to ASP.NET Core isn\u2019t advisable. Web Forms is inextricably tied to System.Web.dll and IIS, so it will likely never be available in ASP.NET Core. Converting an application to ASP.NET Core e\ufb00ectively involves rewriting the application from scratch, not only shifting frameworks, but also potentially shifting design paradigms.<\/p>\n<p>\u5982\u679c\u60a8\u6709 ASP.NET Web Forms \u5e94\u7528\u7a0b\u5e8f\uff0c\u5219\u4e0d\u5efa\u8bae\u5c1d\u8bd5\u5c06\u5176\u76f4\u63a5\u8f6c\u6362\u4e3a ASP.NET Core\u3002Web \u8868\u5355\u4e0e System.Web.dll \u548c IIS \u6709\u7740\u5343\u4e1d\u4e07\u7f15\u7684\u8054\u7cfb\uff0c\u56e0\u6b64\u5b83\u53ef\u80fd\u6c38\u8fdc\u4e0d\u4f1a\u5728 ASP.NET Core \u4e2d\u63d0\u4f9b\u3002\u5c06\u5e94\u7528\u7a0b\u5e8f\u6709\u6548\u5730\u8f6c\u6362\u4e3a ASP.NET Core \u6d89\u53ca\u4ece\u5934\u5f00\u59cb\u91cd\u5199\u5e94\u7528\u7a0b\u5e8f\uff0c\u4e0d\u4ec5\u8981\u6539\u53d8\u6846\u67b6\uff0c\u8fd8\u53ef\u80fd\u6539\u53d8\u8bbe\u8ba1\u8303\u5f0f\u3002<\/p>\n<p>All is not lost, however. Blazor server provides a stateful, component-based application that\u2019s similar to the Web Forms application model. You may be able to gradually migrate your Web Forms application page by page to an ASP.NET Core Blazor server application.4 Alternatively, you could slowly introduce web API concepts into your Web Forms application, reducing the reliance on legacy Web Forms constructs such as ViewState, with the goal of ultimately moving to an ASP.NET Core web API application.<\/p>\n<p>\u7136\u800c\uff0c\u4e00\u5207\u90fd\u6ca1\u6709\u5931\u53bb\u3002Blazor \u670d\u52a1\u5668\u63d0\u4f9b\u57fa\u4e8e\u7ec4\u4ef6\u7684\u6709\u72b6\u6001\u5e94\u7528\u7a0b\u5e8f\uff0c\u5b83\u7c7b\u4f3c\u4e8e Web Forms \u5e94\u7528\u7a0b\u5e8f\u6a21\u578b\u3002\u4f60\u53ef\u4ee5\u9010\u6b65\u9010\u9875\u5c06 Web \u7a97\u4f53\u5e94\u7528\u7a0b\u5e8f\u8fc1\u79fb\u5230 ASP.NET Core Blazor \u670d\u52a1\u5668\u5e94\u7528\u7a0b\u5e8f\u30024 \u6216\u8005\uff0c\u60a8\u53ef\u4ee5\u6162\u6162\u5730\u5c06 Web API \u6982\u5ff5\u5f15\u5165 Web \u7a97\u4f53\u5e94\u7528\u7a0b\u5e8f\uff0c\u4ece\u800c\u51cf\u5c11\u5bf9\u65e7\u7248 Web \u7a97\u4f53\u6784\u9020\uff08\u5982 ViewState\uff09\u7684\u4f9d\u8d56\uff0c\u6700\u7ec8\u8fc1\u79fb\u5230 ASP.NET Core Web API \u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>Windows Communication Foundation (WCF) is only partially supported in ASP.NET Core. It\u2019s possible to build client-side WCF services using the libraries provided by ASP.NET Core (<a href=\"https:\/\/github.com\/dotnet\/wcf\">https:\/\/github.com\/dotnet\/wcf<\/a>) and to build server-side WCF services by using the Microsoft-supported community-driven project CoreWCF.5 These libraries don\u2019t support all the APIs available in .NET Framework WCF (distributed transactions and some message security formats, for example), so if you absolutely need those APIs, it may be best to avoid ASP.NET Core for now.<\/p>\n<p>\u670d\u52a1\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528 Microsoft \u652f\u6301\u7684\u793e\u533a\u9a71\u52a8\u9879\u76ee CoreWCF \u6784\u5efa\u670d\u52a1\u5668\u7aef WCF \u670d\u52a1\u30025 \u8fd9\u4e9b\u5e93\u4e0d\u652f\u6301 .NET Framework WCF \u4e2d\u63d0\u4f9b\u7684\u6240\u6709 API\uff08\u4f8b\u5982\uff0c\u5206\u5e03\u5f0f\u4e8b\u52a1\u548c\u67d0\u4e9b\u6d88\u606f\u5b89\u5168\u683c\u5f0f\uff09\uff0c\u56e0\u6b64\uff0c\u5982\u679c\u60a8\u7edd\u5bf9\u9700\u8981\u8fd9\u4e9b API\uff0c\u6700\u597d\u6682\u65f6\u907f\u514d\u4f7f\u7528 ASP.NET Core\u3002<\/p>\n<p><strong>TIP<\/strong> If you like WCF\u2019s contract-based RPC-style of programming but don\u2019t have a hard requirement for WCF itself, consider using gRPC instead. gRPC is a modern RPC framework with many concepts that are similar to WCF, and it\u2019s supported by ASP.NET Core out of the box (<a href=\"http:\/\/mng.bz\/wv9Q\">http:\/\/mng.bz\/wv9Q<\/a>).<\/p>\n<p><strong>\u63d0\u793a<\/strong> \u5982\u679c\u60a8\u559c\u6b22 WCF \u57fa\u4e8e\u534f\u5b9a\u7684 RPC \u6837\u5f0f\u7f16\u7a0b\uff0c\u4f46\u5bf9 WCF \u672c\u8eab\u6ca1\u6709\u786c\u6027\u8981\u6c42\uff0c\u8bf7\u8003\u8651\u6539\u7528 gRPC\u3002gRPC \u662f\u4e00\u4e2a\u73b0\u4ee3 RPC \u6846\u67b6\uff0c\u5177\u6709\u8bb8\u591a\u4e0e WCF \u7c7b\u4f3c\u7684\u6982\u5ff5\uff0c\u5e76\u4e14\u5b83\u7531\u5f00\u7bb1\u5373\u7528\u7684 ASP.NET Core \uff08<a href=\"http:\/\/mng.bz\/wv9Q\">http:\/\/mng.bz\/wv9Q<\/a>\uff09 \u63d0\u4f9b\u652f\u6301\u3002<\/p>\n<p>If your existing application is complex and makes extensive use of the previous MVC or web API extensibility points or message handlers, porting your application to ASP.NET Core may be more di\ufb03cult. ASP.NET Core is built with many features similar to the previous version of ASP.NET MVC, but the underlying architecture is di\ufb00erent. Several of the previous features don\u2019t have direct replacements, so they\u2019ll require rethinking.<\/p>\n<p>\u5982\u679c\u73b0\u6709\u5e94\u7528\u7a0b\u5e8f\u5f88\u590d\u6742\uff0c\u5e76\u4e14\u5e7f\u6cdb\u4f7f\u7528\u4ee5\u524d\u7684 MVC \u6216 Web API \u6269\u5c55\u70b9\u6216\u6d88\u606f\u5904\u7406\u7a0b\u5e8f\uff0c\u5219\u5c06\u5e94\u7528\u7a0b\u5e8f\u79fb\u690d\u5230 ASP.NET Core \u53ef\u80fd\u4f1a\u66f4\u52a0\u56f0\u96be\u3002ASP.NET Core \u5177\u6709\u8bb8\u591a\u4e0e\u4ee5\u524d\u7248\u672c\u7684 ASP.NET MVC \u7c7b\u4f3c\u7684\u529f\u80fd\uff0c\u4f46\u5e95\u5c42\u67b6\u6784\u4e0d\u540c\u3002\u524d\u9762\u7684\u51e0\u4e2a\u529f\u80fd\u6ca1\u6709\u76f4\u63a5\u66ff\u6362\uff0c\u56e0\u6b64\u9700\u8981\u91cd\u65b0\u8003\u8651\u3002<\/p>\n<p>The larger the application is, the greater the di\ufb03culty you\u2019re likely to have converting your application to ASP.NET Core.Microsoft itself suggests that porting an application from ASP.NET MVC to ASP.NET Core is at least as big a rewrite as porting from ASP.NET Web Forms to ASP.NET MVC. If that suggestion doesn\u2019t scare you, nothing will!<\/p>\n<p>\u5e94\u7528\u7a0b\u5e8f\u8d8a\u5927\uff0c\u5c06\u5e94\u7528\u7a0b\u5e8f\u8f6c\u6362\u4e3a ASP.NET Core \u7684\u96be\u5ea6\u5c31\u8d8a\u5927\u3002<br \/>\nMicrosoft\u672c\u8eab\u8868\u660e\uff0c\u5c06\u5e94\u7528\u7a0b\u5e8f\u4ece ASP.NET MVC \u79fb\u690d\u5230 ASP.NET Core \u81f3\u5c11\u4e0e\u4ece ASP.NET Web Forms \u79fb\u690d\u5230 ASP.NET MVC \u4e00\u6837\u5927\u3002\u5982\u679c\u8fd9\u4e2a\u5efa\u8bae\u6ca1\u6709\u5413\u5230\u4f60\uff0c\u90a3\u5c31\u4ec0\u4e48\u90fd\u4e0d\u4f1a\u4e86\uff01<\/p>\n<p>If an application is rarely used, isn\u2019t part of your core business, or won\u2019t need signi\ufb01cant development in the near term, I suggest that you don\u2019t try to convert it to ASP.NET Core. Microsoft will support .NET Framework for the foreseeable future (Windows itself depends on it!), and the<br \/>\npayo\ufb00 in converting these fringe applications is unlikely to be worth the e\ufb00ort.<\/p>\n<p>\u5982\u679c\u67d0\u4e2a\u5e94\u7528\u7a0b\u5e8f\u5f88\u5c11\u4f7f\u7528\uff0c\u4e0d\u662f\u60a8\u7684\u6838\u5fc3\u4e1a\u52a1\u7684\u4e00\u90e8\u5206\uff0c\u6216\u8005\u5728\u77ed\u671f\u5185\u4e0d\u9700\u8981\u91cd\u5927\u5f00\u53d1\uff0c\u6211\u5efa\u8bae\u60a8\u4e0d\u8981\u5c1d\u8bd5\u5c06\u5176\u8f6c\u6362\u4e3a ASP.NET Core\u3002Microsoft \u5c06\u5728\u53ef\u9884\u89c1\u7684\u5c06\u6765\u652f\u6301 .NET Framework\uff08Windows \u672c\u8eab\u4f9d\u8d56\u4e8e\u5b83\uff01\uff09\uff0c\u5e76\u4e14<\/p>\n<p>\u8f6c\u6362\u8fd9\u4e9b\u8fb9\u7f18\u5e94\u7528\u7a0b\u5e8f\u7684\u56de\u62a5\u4e0d\u592a\u53ef\u80fd\u503c\u5f97\u4ed8\u51fa\u52aa\u529b\u3002<\/p>\n<p>So when should you port an application to ASP.NET Core? As I\u2019ve already mentioned, the best opportunity to get started is on small new green\ufb01eld projects instead of existing applications. That said, if the existing application in question is small or will need signi\ufb01cant future development, porting may be a good option.<\/p>\n<p>\u90a3\u4e48\uff0c\u4f55\u65f6\u5e94\u5c06\u5e94\u7528\u7a0b\u5e8f\u79fb\u690d\u5230 ASP.NET Core\uff1f\u6b63\u5982\u6211\u5df2\u7ecf\u63d0\u5230\u7684\uff0c\u6700\u597d\u7684\u5f00\u59cb\u673a\u4f1a\u662f\u5c0f\u578b\u7684\u65b0\u7eff\u5730\u9879\u76ee\uff0c\u800c\u4e0d\u662f\u73b0\u6709\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c\u73b0\u6709\u5e94\u7528\u7a0b\u5e8f\u5f88\u5c0f\u6216\u672a\u6765\u9700\u8981\u5927\u91cf\u5f00\u53d1\uff0c\u5219\u79fb\u690d\u53ef\u80fd\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u9009\u62e9\u3002<\/p>\n<p>It\u2019s always best to work in small iterations if possible when porting an application, rather than attempt to convert the entire application at the same time. Luckily, Microsoft provides tools for that purpose. A set of System.Web adapters, a .NET-based reverse proxy called YARP (Yet Another Reverse Proxy; <a href=\"http:\/\/mng.bz\/qr92\">http:\/\/mng.bz\/qr92<\/a>), and tooling built into Visual Studio can help you implement the strangler \ufb01g pattern (<a href=\"http:\/\/mng.bz\/rW6J\">http:\/\/mng.bz\/rW6J<\/a>). This tooling allows you to migrate your application one page\/API at a time, reducing the risk associated with porting an ASP.NET application to ASP.NET Core.<\/p>\n<p>\u5728\u79fb\u690d\u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u5982\u679c\u53ef\u80fd\u7684\u8bdd\uff0c\u6700\u597d\u5728\u5c0f\u8fed\u4ee3\u4e2d\u5de5\u4f5c\uff0c\u800c\u4e0d\u662f\u5c1d\u8bd5\u540c\u65f6\u8f6c\u6362\u6574\u4e2a\u5e94\u7528\u7a0b\u5e8f\u3002\u5e78\u8fd0\u7684\u662f\uff0cMicrosoft \u63d0\u4f9b\u4e86\u7528\u4e8e\u6b64\u76ee\u7684\u7684\u5de5\u5177\u3002\u4e00\u7ec4 System.Web \u9002\u914d\u5668\u3001\u4e00\u4e2a .\u57fa\u4e8e NET \u7684\u53cd\u5411\u4ee3\u7406\u79f0\u4e3a YARP\uff08Yet Another Reverse Proxy; <a href=\"http:\/\/mng.bz\/qr92\">http:\/\/mng.bz\/qr92<\/a>\uff09 \u548c Visual Studio \u4e2d\u5185\u7f6e\u7684\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u60a8\u5b9e\u73b0 strangler fig \u6a21\u5f0f \uff08<a href=\"http:\/\/mng.bz\/rW6J\uff09\u3002\u501f\u52a9\u6b64\u5de5\u5177\uff0c\u60a8\u53ef\u4ee5\u4e00\u6b21\u8fc1\u79fb\u4e00\u4e2a\u9875\u9762\/API\">http:\/\/mng.bz\/rW6J\uff09\u3002\u501f\u52a9\u6b64\u5de5\u5177\uff0c\u60a8\u53ef\u4ee5\u4e00\u6b21\u8fc1\u79fb\u4e00\u4e2a\u9875\u9762\/API<\/a> \u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u4ece\u800c\u964d\u4f4e\u5c06 ASP.NET \u5e94\u7528\u7a0b\u5e8f\u79fb\u690d\u5230 ASP.NET Core \u7684\u76f8\u5173\u98ce\u9669\u3002<\/p>\n<p>In this chapter, we walked through some of the historical context of ASP.NET Core, as well as some of the advantages of adopting it. In chapter 3, you\u2019ll create your \ufb01rst application from a template and run it. We\u2019ll walk through each of the main components that make up your application and see how they work together to render a web page.\u200c<\/p>\n<p>\u5728\u672c\u7ae0\u4e2d\uff0c\u6211\u4eec\u4ecb\u7ecd\u4e86 ASP.NET Core \u7684\u4e00\u4e9b\u5386\u53f2\u80cc\u666f\uff0c\u4ee5\u53ca\u91c7\u7528\u5b83\u7684\u4e00\u4e9b\u4f18\u52bf\u3002\u5728\u7b2c 3 \u7ae0\u4e2d\uff0c\u60a8\u5c06\u4ece\u6a21\u677f\u521b\u5efa\u7b2c\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\u5e76\u8fd0\u884c\u5b83\u3002\u6211\u4eec\u5c06\u4ecb\u7ecd\u6784\u6210\u5e94\u7528\u7a0b\u5e8f\u7684\u6bcf\u4e2a\u4e3b\u8981\u7ec4\u4ef6\uff0c\u5e76\u4e86\u89e3\u5b83\u4eec\u5982\u4f55\u534f\u540c\u5de5\u4f5c\u4ee5\u5448\u73b0\u7f51\u9875\u3002<\/p>\n<h2>Summary<\/h2>\n<h2>\u603b\u7ed3<\/h2>\n<p>Web frameworks provide a way to build dynamic web applications easily.<br \/>\nWeb \u6846\u67b6\u63d0\u4f9b\u4e86\u4e00\u79cd\u8f7b\u677e\u6784\u5efa\u52a8\u6001 Web \u5e94\u7528\u7a0b\u5e8f\u7684\u65b9\u6cd5\u3002<\/p>\n<p>ASP.NET Core is a web framework built with modern software architecture practices and modularization as its focus.<br \/>\nASP.NET Core \u662f\u4e00\u4e2a\u4ee5\u73b0\u4ee3\u8f6f\u4ef6\u67b6\u6784\u5b9e\u8df5\u548c\u6a21\u5757\u5316\u4e3a\u91cd\u70b9\u6784\u5efa\u7684 Web \u6846\u67b6\u3002<\/p>\n<p>ASP.NET Core runs on the cross-platform .NET 7 platform. You can access Windows-speci\ufb01c features such as the Windows Registry by using the Windows Compatibility Pack.<br \/>\nASP.NET Core \u5728\u8de8\u5e73\u53f0\u7684 .NET 7 \u5e73\u53f0\u4e0a\u8fd0\u884c\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528 Windows \u517c\u5bb9\u5305\u8bbf\u95ee\u7279\u5b9a\u4e8e Windows \u7684\u529f\u80fd\uff0c\u4f8b\u5982 Windows \u6ce8\u518c\u8868\u3002<\/p>\n<p>.NET 5, .NET 6, and .NET 7 are the next versions of .NET Core after .NET Core 3.1.<br \/>\n.NET 5\u3001.NET 6 \u548c .NET 7 \u662f.NET Core 3.1 \u4e4b\u540e\u7684 .NET Core\u7684\u4e0b\u4e00\u4e2a\u7248\u672c\u3002<\/p>\n<p>ASP.NET Core is best used for new green\ufb01eld projects.<br \/>\nASP.NET Core \u6700\u9002\u5408\u7528\u4e8e\u65b0\u7684\u7eff\u5730\u9879\u76ee\u3002<\/p>\n<p>Legacy technologies such as WCF Server and Web Forms can\u2019t be used directly with ASP.NET Core, but they have analogues and supporting libraries that can help with porting ASP.NET applications to ASP.NET Core.<br \/>\nWCF Server \u548c Web Forms \u7b49\u65e7\u6280\u672f\u4e0d\u80fd\u76f4\u63a5\u4e0e ASP.NET Core \u4e00\u8d77\u4f7f\u7528\uff0c\u4f46\u5b83\u4eec\u5177\u6709\u7c7b\u4f3c\u7269\u548c\u652f\u6301\u5e93\uff0c\u53ef\u5e2e\u52a9\u5c06 ASP.NET \u5e94\u7528\u7a0b\u5e8f\u79fb\u690d\u5230 ASP.NET Core\u3002<\/p>\n<p>You can convert an existing ASP.NET application to ASP.NET Core gradually by using the strangler \ufb01g pattern, using tooling and libraries provided by Microsoft.<br \/>\n\u901a\u8fc7\u4f7f\u7528 strangler fig \u6a21\u5f0f\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 Microsoft \u63d0\u4f9b\u7684\u5de5\u5177\u548c\u5e93\uff0c\u9010\u6b65\u5c06\u73b0\u6709\u7684 ASP.NET \u5e94\u7528\u7a0b\u5e8f\u8f6c\u6362\u4e3a ASP.NET Core\u3002<\/p>\n<p>ASP.NET Core apps are often protected from the internet by a reverse-proxy server, which forwards requests to the application.<br \/>\nASP.NET Core \u5e94\u7528\u7a0b\u5e8f\u901a\u5e38\u7531\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668\u4fdd\u62a4\uff0c\u4e0d\u53d7 Internet \u7684\u5f71\u54cd\uff0c\u8be5\u670d\u52a1\u5668\u5c06\u8bf7\u6c42\u8f6c\u53d1\u5230\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<hr \/>\n<p>1.Orchard Core (<a href=\"https:\/\/orchardcore.net\">https:\/\/orchardcore.net<\/a>). Source code at <a href=\"https:\/\/github.com\/OrchardCMS\/OrchardCore\">https:\/\/github.com\/OrchardCMS\/OrchardCore<\/a>.<\/p>\n<p>2.The cloudscribe project (<a href=\"https:\/\/www.cloudscribe.com\">https:\/\/www.cloudscribe.com<\/a>). Source code at <a href=\"https:\/\/github.com\/cloudscribe\">https:\/\/github.com\/cloudscribe<\/a>.<\/p>\n<p>3.As always in web development, technology is in a constant state of \ufb02ux, so these benchmarks will evolve over time. Although ASP.NET Core may not maintain its top-10 slot, you can be sure that performance is one of the key focal points of the ASP.NET Core team.<\/p>\n<p>4.There is a community-driven e\ufb00ort to create Blazor versions of common WebForms components (<a href=\"http:\/\/mng.bz\/PzPP\">http:\/\/mng.bz\/PzPP<\/a>). Also see an e-book for Blazor for Web Forms developers at <a href=\"http:\/\/mng.bz\/JgDv\">http:\/\/mng.bz\/JgDv<\/a>.<\/p>\n<p>5.You can \ufb01nd the CoreWCF libraries at <a href=\"https:\/\/github.com\/corewcf\/corewcf\">https:\/\/github.com\/corewcf\/corewcf<\/a> and details on upgrading a WCF service to .NET 5+ at <a href=\"http:\/\/mng.bz\/mVg2\">http:\/\/mng.bz\/mVg2<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Part 1 Getting started with minimal APIs \u7b2c 1 \u90e8\u5206\uff1a\u5f00\u59cb\u4f7f\u7528\u6700\u5c11\u7684 API Web applications are everywhere these days, from social media web apps and news sites to the apps on your phone. Behind the scenes, there&#8217;s almost always a server running a web application or an HTTP API. Web applications are expected to be infinitely scalable, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[19],"class_list":["post-570","post","type-post","status-publish","format-standard","hentry","category-csharp","tag-asp-net-core-in-action"],"_links":{"self":[{"href":"https:\/\/diji.net\/index.php?rest_route=\/wp\/v2\/posts\/570","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=570"}],"version-history":[{"count":0,"href":"https:\/\/diji.net\/index.php?rest_route=\/wp\/v2\/posts\/570\/revisions"}],"wp:attachment":[{"href":"https:\/\/diji.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=570"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/diji.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=570"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/diji.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=570"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}