{"id":568,"date":"2025-04-05T03:16:50","date_gmt":"2025-04-04T19:16:50","guid":{"rendered":"https:\/\/www.hyy.net\/?p=568"},"modified":"2025-04-05T03:16:50","modified_gmt":"2025-04-04T19:16:50","slug":"asp-net-core-in-action-1-getting-started-with-asp-net-core","status":"publish","type":"post","link":"https:\/\/diji.net\/?p=568","title":{"rendered":"ASP.NET Core in Action 1 Getting started with ASP.NET Core"},"content":{"rendered":"<p>ASP.NET Core in Action 1 Getting started with ASP.NET Core<\/p>\n<h1>1 Getting started with ASP.NET Core<\/h1>\n<h1>1 ASP.NET Core \u5165\u95e8<\/h1>\n<h3>This chapter covers<\/h3>\n<h3>\u672c\u7ae0\u6db5\u76d6<\/h3>\n<ul>\n<li>\n<p>What is ASP.NET Core?<br \/>\n\u4ec0\u4e48\u662f ASP.NET Core\uff1f<\/p>\n<\/li>\n<li>\n<p>Things you can build with ASP.NET Core<br \/>\n\u60a8\u53ef\u4ee5\u4f7f\u7528 ASP.NET Core \u6784\u5efa\u7684\u5185\u5bb9<\/p>\n<\/li>\n<li>\n<p>How ASP.NET Core works<br \/>\nASP.NET Core \u7684\u5de5\u4f5c\u539f\u7406<\/p>\n<\/li>\n<\/ul>\n<p>Choosing to learn and develop with a new framework is a big investment, so it\u2019s important to establish early on whether it\u2019s right for you. In this chapter, I provide some background on ASP.NET Core: what it is, how it works, and why you should consider it for building your web applications.<\/p>\n<p>\u9009\u62e9\u4f7f\u7528\u65b0\u6846\u67b6\u8fdb\u884c\u5b66\u4e60\u548c\u5f00\u53d1\u662f\u4e00\u9879\u5de8\u5927\u7684\u6295\u8d44\uff0c\u56e0\u6b64\u5c3d\u65e9\u786e\u5b9a\u5b83\u662f\u5426\u9002\u5408\u60a8\u975e\u5e38\u91cd\u8981\u3002\u5728\u672c\u7ae0\u4e2d\uff0c\u6211\u5c06\u63d0\u4f9b\u6709\u5173 ASP.NET Core\u7684\u4e00\u4e9b\u80cc\u666f\u77e5\u8bc6\uff1a\u5b83\u662f\u4ec0\u4e48\u3001\u5b83\u662f\u5982\u4f55\u5de5\u4f5c\u7684\uff0c\u4ee5\u53ca\u4e3a\u4ec0\u4e48\u60a8\u5e94\u8be5\u8003\u8651\u4f7f\u7528\u5b83\u6765\u6784\u5efaWeb\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>By the end of this chapter, you should have a good overview of the bene\ufb01ts of ASP.NET Core, the role of .NET 7, and the basic mechanics of how ASP.NET Core works. So without further ado, let\u2019s dive in!<\/p>\n<p>\u5728\u672c\u7ae0\u7ed3\u675f\u65f6\uff0c\u60a8\u5e94\u8be5\u5bf9ASP.NET Core\u7684\u4f18\u52bf\u3001.NET 7\u7684\u4f5c\u7528\u4ee5\u53caASP.NET Core\u5de5\u4f5c\u539f\u7406\u7684\u57fa\u672c\u673a\u5236\u6709\u4e00\u4e2a\u5f88\u597d\u7684\u6982\u8ff0\u3002\u56e0\u6b64\uff0c\u4e8b\u4e0d\u5b9c\u8fdf\uff0c\u8ba9\u6211\u4eec\u5f00\u59cb\u5427\uff01<\/p>\n<h3>1.1 What is ASP.NET Core?\u200c<\/h3>\n<h3>1.1 \u4ec0\u4e48\u662f ASP.NET Core\uff1f<\/h3>\n<p>ASP.NET Core is a cross-platform, open-source application framework that you can use to build dynamic web applications quickly. You can use ASP.NET Core to build server-rendered web applications, backend server applications, HTTP APIs that can be consumed by mobile applications, and much more. ASP.NET Core runs on .NET 7,which is the latest version of .NET Core\u2014a high-performance, cross-platform, open-source runtime.<\/p>\n<p>ASP.NET Core\u662f\u4e00\u4e2a\u8de8\u5e73\u53f0\u7684\u5f00\u6e90\u5e94\u7528\u7a0b\u5e8f\u6846\u67b6\uff0c\u53ef\u7528\u4e8e\u5feb\u901f\u6784\u5efa\u52a8\u6001Web\u5e94\u7528\u7a0b\u5e8f\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528ASP.NET Core\u6784\u5efa\u670d\u52a1\u5668\u6e32\u67d3\u7684Web\u5e94\u7528\u7a0b\u5e8f\u3001\u540e\u7aef\u670d\u52a1\u5668\u5e94\u7528\u7a0b\u5e8f\u3001\u79fb\u52a8\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u4f7f\u7528\u7684HTTP API\u7b49\u7b49\u3002ASP.NET Core\u5728.NET 7\u4e0a\u8fd0\u884c\uff0c\u8fd9\u662f.NET Core\u7684\u6700\u65b0\u7248\u672c\uff0c\u662f\u4e00\u79cd\u9ad8\u6027\u80fd\u3001\u8de8\u5e73\u53f0\u3001\u5f00\u6e90\u8fd0\u884c\u65f6\u3002<\/p>\n<p>ASP.NET Core provides structure, helper functions, and a framework for building applications, which saves you from having to write a lot of this code yourself. Then the ASP.NET Core framework code calls in to your handlers, which in turn call methods in your application\u2019s business logic, as shown in \ufb01gure 1.1. This business logic is the core of your application. You can interact with other services here, such as databases or remote APIs, but your business logic typically doesn\u2019t depend directly on ASP.NET Core.<\/p>\n<p>ASP.NET Core\u63d0\u4f9b\u7ed3\u6784\u3001\u5e2e\u52a9\u7a0b\u5e8f\u51fd\u6570\u548c\u7528\u4e8e\u6784\u5efa\u5e94\u7528\u7a0b\u5e8f\u7684\u6846\u67b6\uff0c\u8fd9\u4f7f\u60a8\u4e0d\u5fc5\u81ea\u5df1\u7f16\u5199\u5927\u91cf\u6b64\u7c7b\u4ee3\u7801\u3002\u7136\u540e\uff0cASP.NET Core\u6846\u67b6\u4ee3\u7801\u8c03\u7528\u60a8\u7684\u5904\u7406\u7a0b\u5e8f\uff0c\u8fd9\u4e9b\u5904\u7406\u7a0b\u5e8f\u53cd\u8fc7\u6765\u8c03\u7528\u5e94\u7528\u7a0b\u5e8f\u4e1a\u52a1\u903b\u8f91\u4e2d\u7684\u65b9\u6cd5\uff0c\u5982\u56fe1.1\u6240\u793a\u3002\u6b64\u4e1a\u52a1\u903b\u8f91\u662f\u5e94\u7528\u7a0b\u5e8f\u7684\u6838\u5fc3\u3002\u60a8\u53ef\u4ee5\u5728\u6b64\u5904\u4e0e\u5176\u4ed6\u670d\u52a1\uff08\u4f8b\u5982\u6570\u636e\u5e93\u6216\u8fdc\u7a0b API\uff09\u8fdb\u884c\u4ea4\u4e92\uff0c\u4f46\u60a8\u7684\u4e1a\u52a1\u903b\u8f91\u901a\u5e38\u4e0d\u76f4\u63a5\u4f9d\u8d56\u4e8eASP.NET Core\u3002<\/p>\n<p><img decoding=\"async\" src=\"\/images\/aspnetcoreinaction\/0101.png\" alt=\"alt text\" \/><\/p>\n<p>Figure 1.1 A typical ASP.NET Core application consists of several layers. The ASP.NET Core framework code handles requests from a client, dealing with the complex networking code. Then the framework calls in to handlers (Razor Pages and Web API controllers, for example) that you write using primitives provided by the framework. Finally, these handlers call in to your application\u2019s domain logic\u2014typically, C# classes and objects without any dependencies that are speci\ufb01c to ASP.NET Core.<br \/>\n\u56fe 1.1 \u5178\u578b\u7684 ASP.NET Core\u5e94\u7528\u7a0b\u5e8f\u7531\u591a\u4e2a\u5c42\u7ec4\u6210\u3002ASP.NET Core\u6846\u67b6\u4ee3\u7801\u5904\u7406\u6765\u81ea\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42\uff0c\u5904\u7406\u590d\u6742\u7684\u7f51\u7edc\u4ee3\u7801\u3002\u7136\u540e\uff0c\u6846\u67b6\u8c03\u7528\u4f7f\u7528\u6846\u67b6\u63d0\u4f9b\u7684\u57fa\u5143\u7f16\u5199\u7684\u5904\u7406\u7a0b\u5e8f\uff08\u4f8b\u5982 Razor Pages\u548cWeb API\u63a7\u5236\u5668\uff09\u3002\u6700\u540e\uff0c\u8fd9\u4e9b\u5904\u7406\u7a0b\u5e8f\u8c03\u7528\u5e94\u7528\u7a0b\u5e8f\u7684\u57df\u903b\u8f91 \u2014 \u901a\u5e38\u662f\u6ca1\u6709\u4efb\u4f55\u7279\u5b9a\u4e8eASP.NET Core\u7684\u4f9d\u8d56\u9879\u7684C#\u7c7b\u548c\u5bf9\u8c61\u3002<\/p>\n<h3>1.2 What types of applications can you build?\u200c<\/h3>\n<h3>1.2 \u60a8\u53ef\u4ee5\u6784\u5efa\u54ea\u4e9b\u7c7b\u578b\u7684\u5e94\u7528\u7a0b\u5e8f\uff1f<\/h3>\n<p>ASP.NET Core provides a generalized web framework that you can use to build a wide variety of applications. ASP.NET Core includes APIs that support many paradigms:<\/p>\n<p>ASP.NET Core \u63d0\u4f9b\u4e86\u4e00\u4e2a\u901a\u7528\u7684 Web \u6846\u67b6\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u6784\u5efa\u5404\u79cd\u5e94\u7528\u7a0b\u5e8f\u3002ASP.NET Core \u5305\u542b\u652f\u6301\u8bb8\u591a\u8303\u4f8b\u7684 API\uff1a<\/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.<br \/>\n\u6700\u5c0f API \u2014 \u53ef\u4f9b\u79fb\u52a8\u5e94\u7528\u7a0b\u5e8f\u6216\u57fa\u4e8e\u6d4f\u89c8\u5668\u7684\u5355\u9875\u5e94\u7528\u7a0b\u5e8f\u4f7f\u7528\u7684\u7b80\u5355 HTTP API\u3002<\/p>\n<\/li>\n<li>\n<p>Web APIs\u2014An alternative approach to 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\u5c0f API \u76f8\u6bd4\uff0c\u5b83\u589e\u52a0\u4e86\u66f4\u591a\u7684\u7ed3\u6784\u548c\u529f\u80fd\u3002<\/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\u6784\u5efa\u9ad8\u6548\u7684\u4e8c\u8fdb\u5236 API\uff0c\u4ee5\u4f7f\u7528 gRPC \u534f\u8bae\u8fdb\u884c\u670d\u52a1\u5668\u5230\u670d\u52a1\u5668\u901a\u4fe1\u3002<\/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\u3002<\/p>\n<\/li>\n<li>\n<p>MVC controllers\u2014Similar to Razor Pages. Model- View-Controller (MVC) controller applications are for server-based applications but without the page- based paradigm.<br \/>\nMVC \u63a7\u5236\u5668 - \u7c7b\u4f3c\u4e8e Razor Pages\u3002\u6a21\u578b-\u89c6\u56fe-\u63a7\u5236\u5668 \uff08MVC\uff09 \u63a7\u5236\u5668\u5e94\u7528\u7a0b\u5e8f\u9002\u7528\u4e8e\u57fa\u4e8e\u670d\u52a1\u5668\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u4f46\u6ca1\u6709\u57fa\u4e8e\u9875\u9762\u7684\u8303\u4f8b\u3002<\/p>\n<\/li>\n<li>\n<p>Blazor WebAssembly\u2014A browser-based single- page application framework that uses the WebAssembly standard, similar to JavaScript frameworks such as Angular, React, and Vue.<br \/>\nBlazor WebAssembly - \u4e00\u79cd\u57fa\u4e8e\u6d4f\u89c8\u5668\u7684\u5355\u9875\u5e94\u7528\u7a0b\u5e8f\u6846\u67b6\uff0c\u5b83\u4f7f\u7528 WebAssembly \u6807\u51c6\uff0c\u7c7b\u4f3c\u4e8e Angular\u3001React \u548c Vue \u7b49 JavaScript \u6846\u67b6\u3002<\/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 single-page application, 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\u5355\u9875\u5e94\u7528\u7a0b\u5e8f\u7684\u611f\u89c9\uff0c\u4f46\u6613\u4e8e\u5f00\u53d1\u670d\u52a1\u5668\u5448\u73b0\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<\/li>\n<\/ul>\n<p>All these paradigms are based on the same building blocks of ASP.NET Core, such as the con\ufb01guration and logging libraries, and then place extra functionality on top. The best paradigm for your application depends on multiple factors, including your API requirements, the details of existing applications you need to interact with, the details of your customers\u2019 browsers and operating environment, and scalability and uptime requirements. You don\u2019t need to choose only one of these paradigms; ASP.NET Core can combine multiple paradigms within a single application.<\/p>\n<p>\u6240\u6709\u8fd9\u4e9b\u8303\u4f8b\u90fd\u57fa\u4e8eASP.NET Core\u7684\u76f8\u540c\u6784\u5efa\u5757\uff0c\u4f8b\u5982\u914d\u7f6e\u548c\u65e5\u5fd7\u8bb0\u5f55\u5e93\uff0c\u7136\u540e\u5c06\u989d\u5916\u7684\u529f\u80fd\u653e\u5728\u9876\u90e8\u3002\u5e94\u7528\u7a0b\u5e8f\u7684\u6700\u4f73\u8303\u4f8b\u53d6\u51b3\u4e8e\u591a\u79cd\u56e0\u7d20\uff0c\u5305\u62ec API \u8981\u6c42\u3001\u9700\u8981\u4e0e\u4e4b\u4ea4\u4e92\u7684\u73b0\u6709\u5e94\u7528\u7a0b\u5e8f\u7684\u8be6\u7ec6\u4fe1\u606f\u3001\u5ba2\u6237\u7684\u6d4f\u89c8\u5668\u548c\u4f5c\u73af\u5883\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u4ee5\u53ca\u53ef\u6269\u5c55\u6027\u548c\u6b63\u5e38\u8fd0\u884c\u65f6\u95f4\u8981\u6c42\u3002\u60a8\u4e0d\u9700\u8981\u53ea\u9009\u62e9\u8fd9\u4e9b\u8303\u4f8b\u4e2d\u7684\u4e00\u4e2a;ASP.NET Core\u53ef\u4ee5\u5728\u5355\u4e2a\u5e94\u7528\u7a0b\u5e8f\u4e2d\u7ec4\u5408\u591a\u4e2a\u8303\u4f8b\u3002<\/p>\n<h3>1.3 Choosing ASP.NET Core\u200c<\/h3>\n<h3>1.3 \u9009\u62e9 ASP.NET Core<\/h3>\n<p>I hope that now you have a general grasp of what ASP.NET Core is and the type of applications you can build with it. But one question remains: should you use it? Microsoft recommends that all new .NET web development use ASP.NET Core, but switching to or learning a new web stack is a big ask for any developer or company.<\/p>\n<p>\u6211\u5e0c\u671b\u73b0\u5728\u60a8\u5df2\u7ecf\u5927\u81f4\u4e86\u89e3\u4e86 ASP.NET Core\u662f\u4ec0\u4e48\u4ee5\u53ca\u60a8\u53ef\u4ee5\u4f7f\u7528\u5b83\u6784\u5efa\u7684\u5e94\u7528\u7a0b\u5e8f\u7c7b\u578b\u3002\u4f46\u4ecd\u7136\u5b58\u5728\u4e00\u4e2a\u95ee\u9898\uff1a\u60a8\u5e94\u8be5\u4f7f\u7528\u5b83\u5417\uff1fMicrosoft\u5efa\u8bae\u6240\u6709\u65b0\u7684.NET Web\u5f00\u53d1\u90fd\u4f7f\u7528 ASP.NET Core\uff0c\u4f46\u5207\u6362\u5230\u6216\u5b66\u4e60\u65b0\u7684 Web \u5806\u6808\u5bf9\u4efb\u4f55\u5f00\u53d1\u4eba\u5458\u6216\u516c\u53f8\u6765\u8bf4\u90fd\u662f\u4e00\u4e2a\u5f88\u5927\u7684\u8981\u6c42\u3002<\/p>\n<p>If you\u2019re new to .NET development and are considering ASP.NET Core, welcome! Microsoft is pushing ASP.NET Core as an attractive option for web development beginners, but taking .NET cross-platform means that it\u2019s competing with many other frameworks on their own turf. ASP.NET Core has many selling points compared with other cross-platform web frameworks:<\/p>\n<p>\u5982\u679c\u4f60\u4e0d\u719f\u6089.NET\u5f00\u53d1\u5e76\u6b63\u5728\u8003\u8651\u4f7f\u7528ASP.NET Core\uff0c\u6b22\u8fce\u4f7f\u7528\uff01Microsoft\u6b63\u5728\u63a8\u52a8 ASP.NET Core\u6210\u4e3a Web \u5f00\u53d1\u521d\u5b66\u8005\u7684\u4e00\u4e2a\u6709\u5438\u5f15\u529b\u7684\u9009\u62e9\uff0c\u4f46\u91c7\u7528 .NET \u8de8\u5e73\u53f0\u610f\u5473\u7740\u5b83\u6b63\u5728\u4e0e\u8bb8\u591a\u5176\u4ed6\u6846\u67b6\u5728\u81ea\u5df1\u7684\u5730\u76d8\u4e0a\u7ade\u4e89\u3002\u4e0e\u5176\u4ed6\u8de8\u5e73\u53f0Web\u6846\u67b6\u76f8\u6bd4\uff0cASP.NET Core\u6709\u5f88\u591a\u5356\u70b9\uff1a<\/p>\n<ul>\n<li>\n<p>It\u2019s a modern, high-performance, open-source web framework.<br \/>\n\u5b83\u662f\u4e00\u4e2a\u73b0\u4ee3\u3001\u9ad8\u6027\u80fd\u3001\u5f00\u6e90\u7684 Web \u6846\u67b6\u3002<\/p>\n<\/li>\n<li>\n<p>It uses familiar design patterns and paradigms.<br \/>\n\u5b83\u4f7f\u7528\u719f\u6089\u7684\u8bbe\u8ba1\u6a21\u5f0f\u548c\u8303\u4f8b\u3002<\/p>\n<\/li>\n<li>\n<p>C# is a great language (but you can use VB.NET or F# if you prefer).<br \/>\nC# \u662f\u4e00\u79cd\u5f88\u597d\u7684\u8bed\u8a00\uff08\u4f46\u5982\u679c\u60a8\u613f\u610f\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528 VB.NET \u6216 F#\uff09\u3002<\/p>\n<\/li>\n<li>\n<p>You can build and run on any platform.<br \/>\n\u60a8\u53ef\u4ee5\u5728\u4efb\u4f55\u5e73\u53f0\u4e0a\u6784\u5efa\u548c\u8fd0\u884c\u3002<\/p>\n<\/li>\n<\/ul>\n<p>ASP.NET Core is a reimagining of the ASP.NET framework, built with modern software design principles on top of the new .NET platform. Although it\u2019s new in one sense, .NET (previously called .NET Core) has had widespread production use since 2016 and has drawn signi\ufb01cantly from the mature, stable, and reliable .NET Framework, which has been used for more than two decades. You can rest easy knowing that by choosing ASP.NET Core and .NET 7, you\u2019re getting a dependable platform as well as a full-featured web framework.<\/p>\n<p>ASP.NET Core\u662f\u5bf9 ASP.NET\u6846\u67b6\u7684\u91cd\u65b0\u6784\u60f3\uff0c\u5728\u65b0\u7684 .NET \u5e73\u53f0\u4e4b\u4e0a\u91c7\u7528\u73b0\u4ee3\u8f6f\u4ef6\u8bbe\u8ba1\u539f\u5219\u6784\u5efa\u3002\u5c3d\u7ba1\u4ece\u67d0\u79cd\u610f\u4e49\u4e0a\u8bf4\uff0c.NET\uff08\u4ee5\u524d\u79f0\u4e3a.NET Core\uff09\u662f\u65b0\u7684\uff0c\u4f46\u5b83\u81ea2016\u5e74\u4ee5\u6765\u5df2\u88ab\u5e7f\u6cdb\u7528\u4e8e\u751f\u4ea7\u9886\u57df\uff0c\u5e76\u4e14\u6781\u5927\u5730\u501f\u9274\u4e86\u5df2\u7ecf\u4f7f\u7528\u4e86\u4e8c\u5341\u591a\u5e74\u7684\u6210\u719f\u3001\u7a33\u5b9a\u548c\u53ef\u9760\u7684.NET Framework\u3002\u60a8\u53ef\u4ee5\u9ad8\u6795\u65e0\u5fe7\uff0c\u56e0\u4e3a\u60a8\u77e5\u9053\u9009\u62e9ASP.NET Core\u548c.NET 7\u5c06\u83b7\u5f97\u4e00\u4e2a\u53ef\u9760\u7684\u5e73\u53f0\u4ee5\u53ca\u4e00\u4e2a\u529f\u80fd\u9f50\u5168\u7684Web\u6846\u67b6\u3002<\/p>\n<p>One major selling point of ASP.NET Core and .NET 7 is the ability to develop and run on any platform. Whether you\u2019re using a Mac, Windows, or Linux computer, you can run the same ASP.NET Core apps and develop across multiple environments. A wide range of distributions are supportedfor Linux users: RHEL, Ubuntu, Debian, CentOS, Fedora, and openSUSE, to name a few. ASP.NET Core even runs on the tiny Alpine distribution, for truly compact deployments to containers, so you can be con\ufb01dent that your operating system of choice will be a viable option.<\/p>\n<p>ASP.NET Core\u548c.NET 7\u7684\u4e00\u4e2a\u4e3b\u8981\u5356\u70b9\u662f\u80fd\u591f\u5728\u4efb\u4f55\u5e73\u53f0\u4e0a\u5f00\u53d1\u548c\u8fd0\u884c\u3002\u65e0\u8bba\u60a8\u4f7f\u7528\u7684\u662f Mac\u3001Windows \u8fd8\u662f Linux \u8ba1\u7b97\u673a\uff0c\u60a8\u90fd\u53ef\u4ee5\u8fd0\u884c\u76f8\u540c\u7684 ASP.NET Core \u5e94\u7528\u7a0b\u5e8f\u5e76\u8de8\u591a\u4e2a\u73af\u5883\u8fdb\u884c\u5f00\u53d1\u3002\u652f\u6301\u591a\u79cd\u53d1\u884c\u7248\u5bf9\u4e8e Linux \u7528\u6237\uff1aRHEL\u3001Ubuntu\u3001Debian\u3001CentOS\u3001Fedora \u548c openSUSE\u7b49\u3002ASP.NET Core\u751a\u81f3\u5728\u5fae\u578bAlpine \u53d1\u884c\u7248\u4e0a\u8fd0\u884c\uff0c\u4ee5\u5b9e\u73b0\u771f\u6b63\u7d27\u51d1\u7684\u5bb9\u5668\u90e8\u7f72\uff0c\u56e0\u6b64\u60a8\u53ef\u4ee5\u786e\u4fe1\u60a8\u9009\u62e9\u7684\u4f5c\u7cfb\u7edf\u5c06\u662f\u4e00\u4e2a\u53ef\u884c\u7684\u9009\u62e9\u3002<\/p>\n<p>If you\u2019re already a .NET developer, the choice of whether to invest in ASP.NET Core for new applications was largely a question of timing. Early versions of .NET Core lacked some features that made it hard to adopt, but that problem no longer exists in the latest versions of .NET. Now Microsoft explicitly advises that all new .NET applications should use.NET 7 (or newer).<\/p>\n<p>\u5982\u679c\u60a8\u5df2\u7ecf\u662f.NET \u5f00\u53d1\u4eba\u5458\uff0c\u90a3\u4e48\u9009\u62e9\u662f\u5426\u4e3a\u65b0\u5e94\u7528\u7a0b\u5e8f\u6295\u8d44 ASP.NET Core\u5728\u5f88\u5927\u7a0b\u5ea6\u4e0a\u662f\u4e00\u4e2a\u65f6\u95f4\u95ee\u9898\u3002\u65e9\u671f\u7248\u672c\u7684.NET Core\u7f3a\u5c11\u4e00\u4e9b\u96be\u4ee5\u91c7\u7528\u7684\u529f\u80fd\uff0c\u4f46\u6700\u65b0\u7248\u672c\u7684.NET \u4e2d\u4e0d\u518d\u5b58\u5728\u8be5\u95ee\u9898\u3002\u73b0\u5728 Microsoft \u660e\u786e\u5efa\u8bae\u6240\u6709\u65b0\u7684.NET \u5e94\u7528\u7a0b\u5e8f\u90fd\u5e94\u8be5\u4f7f\u7528.NET 7\uff08\u6216\u66f4\u9ad8\u7248\u672c\uff09\u3002<\/p>\n<p>Microsoft has pledged to provide bug and security \ufb01xes for the older ASP.NET framework, but it won\u2019t provide any more feature updates. .NET Framework isn\u2019t being removed, so your old applications will continue to work, but you shouldn\u2019t use it for new development.<\/p>\n<p>Microsoft\u5df2\u627f\u8bfa\u4e3a\u8f83\u65e7\u7684ASP.NET\u6846\u67b6\u63d0\u4f9bbug\u548c\u5b89\u5168\u4fee\u590d\uff0c\u4f46\u4e0d\u4f1a\u63d0\u4f9b\u66f4\u591a\u529f\u80fd\u66f4\u65b0\u3002.NET Framework\u672a\u88ab\u5220\u9664\uff0c\u56e0\u6b64\u60a8\u7684\u65e7\u5e94\u7528\u7a0b\u5e8f\u5c06\u7ee7\u7eed\u5de5\u4f5c\uff0c\u4f46\u60a8\u4e0d\u5e94\u5c06\u5176\u7528\u4e8e\u65b0\u7684\u5f00\u53d1\u3002<\/p>\n<p>The main bene\ufb01ts of ASP.NET Core over the previous ASP.NET framework are<\/p>\n<p>\u4e0e\u4ee5\u524d\u7684 ASP.NET \u6846\u67b6\u76f8\u6bd4\uff0cASP.NET Core \u7684\u4e3b\u8981\u4f18\u70b9\u662f<\/p>\n<ul>\n<li>\n<p>Cross-platform development and deployment Focus on performance as a feature<br \/>\n\u8de8\u5e73\u53f0\u5f00\u53d1\u548c\u90e8\u7f72 \u4e13\u6ce8\u4e8e\u6027\u80fd\u4f5c\u4e3a\u4e00\u9879\u529f\u80fd<\/p>\n<\/li>\n<li>\n<p>A simpli\ufb01ed hosting model<br \/>\n\u7b80\u5316\u7684\u6258\u7ba1\u6a21\u578b<\/p>\n<\/li>\n<li>\n<p>Regular releases with a shorter release cycle Open-source<br \/>\n\u53d1\u5e03\u5468\u671f\u66f4\u77ed\u7684\u5e38\u89c4\u7248\u672c\u5f00\u6e90<\/p>\n<\/li>\n<li>\n<p>Modular features<br \/>\n\u6a21\u5757\u5316\u529f\u80fd<\/p>\n<\/li>\n<li>\n<p>More application paradigm options<br \/>\n\u66f4\u591a\u5e94\u7528\u7a0b\u5e8f\u8303\u4f8b\u9009\u9879<\/p>\n<\/li>\n<li>\n<p>The option to package .NET with an app when publishing for standalone deployments<br \/>\n\u5728\u53d1\u5e03\u72ec\u7acb\u90e8\u7f72\u65f6\u5c06 .NET \u4e0e\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u7684\u9009\u9879<\/p>\n<\/li>\n<\/ul>\n<p>As an existing .NET developer who\u2019s moving to ASP.NET Core, your ability to build and deploy cross-platform opens the door to a whole new avenue of applications, such as taking advantage of cheaper Linux virtual machine hosting in the cloud, using Docker containers for repeatable continuous integration, or writing .NET code on your Mac without needing to run a Windows virtual machine. ASP.NET Core, in combination with .NET 7, makes all this possible.<\/p>\n<p>\u4f5c\u4e3a\u6b63\u5728\u8fc1\u79fb\u5230 ASP.NET Core\u7684\u73b0\u6709 .NET \u5f00\u53d1\u4eba\u5458\uff0c\u60a8\u6784\u5efa\u548c\u90e8\u7f72\u8de8\u5e73\u53f0\u7684\u80fd\u529b\u4e3a\u5168\u65b0\u7684\u5e94\u7528\u7a0b\u5e8f\u9014\u5f84\u6253\u5f00\u4e86\u5927\u95e8\uff0c\u4f8b\u5982\u5229\u7528\u4e91\u4e2d\u66f4\u4fbf\u5b9c\u7684 Linux \u865a\u62df\u673a\u6258\u7ba1\uff0c\u4f7f\u7528 Docker \u5bb9\u5668\u8fdb\u884c\u53ef\u91cd\u590d\u7684\u6301\u7eed\u96c6\u6210\uff0c\u6216\u8005\u5728 Mac \u4e0a\u7f16\u5199 .NET \u4ee3\u7801\u800c\u65e0\u9700\u8fd0\u884c Windows \u865a\u62df\u673a\u3002ASP.NET Core \u4e0e .NET 7 \u76f8\u7ed3\u5408\uff0c\u4f7f\u8fd9\u4e00\u5207\u6210\u4e3a\u53ef\u80fd\u3002<\/p>\n<p>That\u2019s not to say that your experience deploying ASP.NET applications to Windows and Internet Information Services (IIS) is wasted. On the contrary, ASP.NET Core uses many of the same concepts as the previous ASP.NET framework, and you can still run your ASP.NET Core applications in IIS, so moving to ASP.NET Core doesn\u2019t mean starting from scratch.\u200c<\/p>\n<p>\u8fd9\u5e76\u4e0d\u662f\u8bf4\u60a8\u5c06 ASP.NET \u5e94\u7528\u7a0b\u5e8f\u90e8\u7f72\u5230 Windows \u548c Internet Information Services \uff08IIS\uff09 \u7684\u7ecf\u9a8c\u662f\u6d6a\u8d39\u7684\u3002\u76f8\u53cd\uff0cASP.NET Core \u4f7f\u7528\u8bb8\u591a\u4e0e\u4ee5\u524d\u7684 ASP.NET \u6846\u67b6\u76f8\u540c\u7684\u6982\u5ff5\uff0c\u5e76\u4e14\u4f60\u4ecd\u7136\u53ef\u4ee5\u5728 IIS \u4e2d\u8fd0\u884c ASP.NET Core \u5e94\u7528\u7a0b\u5e8f\uff0c\u56e0\u6b64\u8fc1\u79fb\u5230 ASP.NET Core \u5e76\u4e0d\u610f\u5473\u7740\u4ece\u5934\u5f00\u59cb\u3002<\/p>\n<h3>1.4 How does ASP.NET Core work?\u200c<\/h3>\n<h3>1.4 ASP.NET Core \u7684\u5de5\u4f5c\u539f\u7406\u662f\u4ec0\u4e48\uff1f<\/h3>\n<p>I\u2019ve covered the basics of what ASP.NET Core is, what you can use it for, and why you should consider using it. In this section, you\u2019ll see how an application built with ASP.NET Core works, from a user request for a URL to the display of a page in the browser. To get there, \ufb01rst you\u2019ll see how an HTTP request works for any web server; then you\u2019ll see how ASP.NET Core extends the process to create dynamic web pages.<\/p>\n<p>\u6211\u5df2\u7ecf\u4ecb\u7ecd\u4e86 ASP.NET Core \u662f\u4ec0\u4e48\u3001\u5b83\u53ef\u4ee5\u7528\u4e8e\u4ec0\u4e48\u4ee5\u53ca\u4e3a\u4ec0\u4e48\u5e94\u8be5\u8003\u8651\u4f7f\u7528\u5b83\u7684\u57fa\u7840\u77e5\u8bc6\u3002\u5728\u672c\u8282\u4e2d\uff0c\u60a8\u5c06\u4e86\u89e3\u4f7f\u7528 ASP.NET Core \u6784\u5efa\u7684\u5e94\u7528\u7a0b\u5e8f\u7684\u5de5\u4f5c\u539f\u7406\uff0c\u4ece\u7528\u6237\u5bf9 URL \u7684\u8bf7\u6c42\u5230\u6d4f\u89c8\u5668\u4e2d\u7684\u9875\u9762\u663e\u793a\u3002\u8981\u5230\u8fbe\u90a3\u91cc\uff0c\u9996\u5148\u60a8\u5c06\u4e86\u89e3 HTTP \u8bf7\u6c42\u5982\u4f55\u9002\u7528\u4e8e\u4efb\u4f55 Web \u670d\u52a1\u5668;\u7136\u540e\uff0c\u60a8\u5c06\u770b\u5230 ASP.NET Core \u5982\u4f55\u6269\u5c55\u521b\u5efa\u52a8\u6001\u7f51\u9875\u7684\u8fc7\u7a0b\u3002<\/p>\n<h4>1.4.1 How does an HTTP web request work?\u200c<\/h4>\n<h4>1.4.1 HTTP Web \u8bf7\u6c42\u5982\u4f55\u5de5\u4f5c\uff1f<\/h4>\n<p>As you know now, ASP.NET Core is a framework for building web applications that serve data from a server. One of the most common scenarios for web developers is building a web app that you can view in a web browser. Figure 1.2 shows the high-level process you can expect from any web server.<\/p>\n<p>\u6b63\u5982\u60a8\u73b0\u5728\u6240\u77e5\uff0cASP.NET Core \u662f\u4e00\u4e2a\u6846\u67b6\uff0c\u7528\u4e8e\u6784\u5efa\u4ece\u670d\u52a1\u5668\u63d0\u4f9b\u6570\u636e\u7684 Web \u5e94\u7528\u7a0b\u5e8f\u3002\u5bf9\u4e8e Web \u5f00\u53d1\u4eba\u5458\u6765\u8bf4\uff0c\u6700\u5e38\u89c1\u7684\u65b9\u6848\u4e4b\u4e00\u662f\u6784\u5efa\u53ef\u5728 Web \u6d4f\u89c8\u5668\u4e2d\u67e5\u770b\u7684 Web \u5e94\u7528\u7a0b\u5e8f\u3002\u56fe 1.2 \u663e\u793a\u4e86\u60a8\u53ef\u4ee5\u4ece\u4efb\u4f55 Web \u670d\u52a1\u5668\u83b7\u5f97\u7684\u9ad8\u7ea7\u8fc7\u7a0b\u3002<\/p>\n<p><img decoding=\"async\" src=\"\/images\/aspnetcoreinaction\/0102.png\" alt=\"alt text\" \/><\/p>\n<p>Figure 1.2 Requesting a web page. The user starts by requesting a web page, which causes an HTTP request to be sent to the server. The server interprets the request, generates the necessary HTML, and sends it back in an HTTP response. Then the browser can display the web page.<\/p>\n<p>\u56fe 1.2 \u8bf7\u6c42\u7f51\u9875\u3002\u7528\u6237\u9996\u5148\u8bf7\u6c42\u4e00\u4e2a\u7f51\u9875\uff0c\u8fd9\u4f1a\u5bfc\u81f4\u5411\u670d\u52a1\u5668\u53d1\u9001 HTTP \u8bf7\u6c42\u3002\u670d\u52a1\u5668\u89e3\u91ca\u8bf7\u6c42\uff0c\u751f\u6210\u5fc5\u8981\u7684 HTML\uff0c\u5e76\u5728 HTTP \u54cd\u5e94\u4e2d\u5c06\u5176\u53d1\u9001\u56de\u3002\u7136\u540e\u6d4f\u89c8\u5668\u53ef\u4ee5\u663e\u793a\u7f51\u9875\u3002<\/p>\n<p>The process begins when a user navigates to a website or types a URL in their browser. The URL or web address consists of a hostname and a path to some resource on the web app. Navigating to the address in the browser sends a request from the user\u2019s computer to the server on which the web app is hosted, using the HTTP protocol.<\/p>\n<p>\u5f53\u7528\u6237\u5bfc\u822a\u5230\u7f51\u7ad9\u6216\u5728\u6d4f\u89c8\u5668\u4e2d\u952e\u5165 URL \u65f6\uff0c\u8be5\u8fc7\u7a0b\u5f00\u59cb\u3002URL \u6216 Web \u5730\u5740\u7531\u4e3b\u673a\u540d\u548c Web \u5e94\u7528\u7a0b\u5e8f\u4e0a\u67d0\u4e2a\u8d44\u6e90\u7684\u8def\u5f84\u7ec4\u6210\u3002\u5bfc\u822a\u5230\u6d4f\u89c8\u5668\u4e2d\u7684\u5730\u5740\u4f1a\u4f7f\u7528 HTTP \u534f\u8bae\u5c06\u8bf7\u6c42\u4ece\u7528\u6237\u7684\u8ba1\u7b97\u673a\u53d1\u9001\u5230\u6258\u7ba1 Web \u5e94\u7528\u7a0b\u5e8f\u7684\u670d\u52a1\u5668\u3002<\/p>\n<p><strong>DEFINITION<\/strong> The hostname of a website uniquely identi\ufb01es its location on the internet by mapping via the Domain Name Service (DNS) to an IP address. Examples include microsoft.com, www.google.co.uk, and facebook.com.<\/p>\n<p><strong>\u5b9a\u4e49<\/strong> \u7f51\u7ad9\u7684\u4e3b\u673a\u540d\u901a\u8fc7\u57df\u540d\u670d\u52a1 \uff08DNS\uff09 \u6620\u5c04\u5230 IP \u5730\u5740\uff0c\u4ece\u800c\u552f\u4e00\u6807\u8bc6\u5176\u5728 Internet \u4e0a\u7684\u4f4d\u7f6e\u3002\u793a\u4f8b\u5305\u62ec microsoft.com\u3001www.google.co.uk \u548c facebook.com\u3002<\/p>\n<blockquote>\n<p>A brief primer on HTTP<br \/>\nHTTP \u7b80\u4ecb<br \/>\nHypertext Transfer Protocol (HTTP) is the application-level protocol that powers the web. It\u2019s a stateless request-response protocol whereby a client machine sends a request to a server, which sends a response in turn.<br \/>\n\u8d85\u6587\u672c\u4f20\u8f93\u534f\u8bae \uff08HTTP\uff09 \u662f\u652f\u6301 Web \u7684\u5e94\u7528\u7a0b\u5e8f\u7ea7\u534f\u8bae\u3002\u5b83\u662f\u4e00\u79cd\u65e0\u72b6\u6001\u7684\u8bf7\u6c42-\u54cd\u5e94\u534f\u8bae\uff0c\u5ba2\u6237\u7aef\u8ba1\u7b97\u673a\u901a\u8fc7\u8be5\u534f\u8bae\u5411\u670d\u52a1\u5668\u53d1\u9001\u8bf7\u6c42\uff0c\u670d\u52a1\u5668\u53cd\u8fc7\u6765\u53d1\u9001\u54cd\u5e94\u3002<br \/>\nEvery HTTP request consists of a verb indicating the type of the request and a path indicating the resource to interact with. A request typically also includes headers, which are key-value pairs, and in some cases a body, such as the contents of a form, when sending data to the server.\u200c\u200c<br \/>\n\u6bcf\u4e2a HTTP \u8bf7\u6c42\u90fd\u5305\u542b\u4e00\u4e2a\u52a8\u8bcd\uff08\u6307\u793a\u8bf7\u6c42\u7684\u7c7b\u578b\uff09\u548c\u4e00\u4e2a\u8def\u5f84\uff08\u6307\u793a\u8981\u4e0e\u4e4b\u4ea4\u4e92\u7684\u8d44\u6e90\uff09\u3002\u5728\u5411\u670d\u52a1\u5668\u53d1\u9001\u6570\u636e\u65f6\uff0c\u8bf7\u6c42\u901a\u5e38\u8fd8\u5305\u62ec\u6807\u5934\uff08\u952e\u503c\u5bf9\uff09\u548c\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u7684\u6b63\u6587\uff0c\u4f8b\u5982\u8868\u5355\u7684\u5185\u5bb9\u3002<br \/>\nAn HTTP response contains a status code, indicating whether the request was successful, and optionally headers and a body.<br \/>\nHTTP \u54cd\u5e94\u5305\u542b\u72b6\u6001\u4ee3\u7801\uff0c\u6307\u793a\u8bf7\u6c42\u662f\u5426\u6210\u529f\uff0c\u4ee5\u53ca\u53ef\u9009\u7684\u6807\u5934\u548c\u6b63\u6587\u3002<br \/>\nFor a more detailed look at the HTTP protocol itself, as well as more examples, see section 1.3 (\u201cA quick introduction to HTTP\u201d) of Go Web Programming, by Sau Sheong Chang (Manning, 2016), at <a href=\"http:\/\/mng.bz\/x4mB\">http:\/\/mng.bz\/x4mB<\/a>. You can also read the raw RFC speci\ufb01cation at <a href=\"https:\/\/www.rfc-editor.org\/rfc\/rfc9110.txt\">https:\/\/www.rfc-editor.org\/rfc\/rfc9110.txt<\/a> if dense text is your thing!\u200c<br \/>\n\u6709\u5173 HTTP \u534f\u8bae\u672c\u8eab\u7684\u66f4\u8be6\u7ec6\u5185\u5bb9\u4ee5\u53ca\u66f4\u591a\u793a\u4f8b\uff0c\u8bf7\u53c2\u9605 Sau Sheong Chang \uff08Manning\uff0c 2016\uff09 \u5728 <a href=\"http:\/\/mng.bz\/x4mB\">http:\/\/mng.bz\/x4mB<\/a> \u4e0a\u7f16\u5199\u7684 Go Web Programming \u7684\u7b2c 1.3 \u8282\uff08\u201cHTTP \u5feb\u901f\u4ecb\u7ecd\u201d\uff09\u3002 \u60a8\u8fd8\u53ef\u4ee5\u9605\u8bfb\u539f\u59cb RFC \u89c4\u8303\uff0c<a href=\"https:\/\/www.rfc-editor.org\/rfc\/rfc9110.txt\">https:\/\/www.rfc-editor.org\/rfc\/rfc9110.txt<\/a> \u5982\u679c\u60a8\u559c\u6b22\u5bc6\u96c6\u6587\u672c\uff01<\/p>\n<\/blockquote>\n<p>The request passes through the internet, potentially to the other side of the world, until it \ufb01nally makes its way to the server associated with the given hostname, on which the web app is running. The request is potentially received and rebroadcast at multiple routers along the way, but only when it reaches the server associated with the hostname is the request processed.<\/p>\n<p>\u8be5\u8bf7\u6c42\u901a\u8fc7 Internet \u4f20\u9012\uff0c\u53ef\u80fd\u5230\u8fbe\u4e16\u754c\u7684\u53e6\u4e00\u7aef\uff0c\u76f4\u5230\u6700\u7ec8\u5230\u8fbe\u4e0e\u8fd0\u884c Web \u5e94\u7528\u7a0b\u5e8f\u7684\u7ed9\u5b9a\u4e3b\u673a\u540d\u5173\u8054\u7684\u670d\u52a1\u5668\u3002\u8bf7\u6c42\u53ef\u80fd\u4f1a\u5728\u9014\u4e2d\u7684\u591a\u4e2a\u8def\u7531\u5668\u4e0a\u63a5\u6536\u5e76\u91cd\u65b0\u5e7f\u64ad\uff0c\u4f46\u53ea\u6709\u5f53\u5b83\u5230\u8fbe\u4e0e\u4e3b\u673a\u540d\u5173\u8054\u7684\u670d\u52a1\u5668\u65f6\uff0c\u624d\u4f1a\u5904\u7406\u8bf7\u6c42\u3002<\/p>\n<p>When the server receives the request, it processes that request and generates an HTTP response. Depending on the request, this response could be a web page, an image, a JavaScript \ufb01le, a simple acknowledgment, or practically any other \ufb01le. For this example, I\u2019ll assume that the user has reached the home page of a web app, so the server responds with some HTML. The HTML is added to the HTTP response, which is sent back across the internet to the browser that made the request.<\/p>\n<p>\u5f53\u670d\u52a1\u5668\u6536\u5230\u8bf7\u6c42\u65f6\uff0c\u5b83\u4f1a\u5904\u7406\u8be5\u8bf7\u6c42\u5e76\u751f\u6210 HTTP \u54cd\u5e94\u3002\u6839\u636e\u8bf7\u6c42\uff0c\u6b64\u54cd\u5e94\u53ef\u4ee5\u662f\u7f51\u9875\u3001\u56fe\u50cf\u3001JavaScript \u6587\u4ef6\u3001\u7b80\u5355\u786e\u8ba4\u6216\u51e0\u4e4e\u4efb\u4f55\u5176\u4ed6\u6587\u4ef6\u3002\u5bf9\u4e8e\u6b64\u793a\u4f8b\uff0c\u6211\u5047\u8bbe\u7528\u6237\u5177\u6709\u5230\u8fbe Web \u5e94\u7528\u7a0b\u5e8f\u7684\u4e3b\u9875\uff0c\u56e0\u6b64\u670d\u52a1\u5668\u4f7f\u7528\u4e00\u4e9b HTML \u8fdb\u884c\u54cd\u5e94\u3002HTML \u5c06\u6dfb\u52a0\u5230 HTTP \u54cd\u5e94\u4e2d\uff0c\u8be5\u54cd\u5e94\u5c06\u901a\u8fc7 Internet \u53d1\u9001\u56de\u53d1\u51fa\u8bf7\u6c42\u7684\u6d4f\u89c8\u5668\u3002<\/p>\n<p>As soon as the user\u2019s browser begins receiving the HTTP response, it can start displaying content on the screen, but the HTML page may also reference other pages and links on the server. To display the complete web page instead of a static, colorless, raw HTML \ufb01le, the browser must repeat the request process, fetching every referenced \ufb01le. HTML, images, Cascading Style Sheets (CSS) for styling, and JavaScript \ufb01les for extra behavior are all fetched using exactly the same HTTP request process.<\/p>\n<p>\u4e00\u65e6\u7528\u6237\u7684\u6d4f\u89c8\u5668\u5f00\u59cb\u63a5\u6536 HTTP \u54cd\u5e94\uff0c\u5b83\u5c31\u53ef\u4ee5\u5f00\u59cb\u5728\u5c4f\u5e55\u4e0a\u663e\u793a\u5185\u5bb9\uff0c\u4f46 HTML \u9875\u9762\u4e5f\u53ef\u80fd\u5f15\u7528\u670d\u52a1\u5668\u4e0a\u7684\u5176\u4ed6\u9875\u9762\u548c\u94fe\u63a5\u3002\u8981\u663e\u793a\u5b8c\u6574\u7684\u7f51\u9875\u800c\u4e0d\u662f\u9759\u6001\u7684\u3001\u65e0\u8272\u7684\u539f\u59cb HTML \u6587\u4ef6\uff0c\u6d4f\u89c8\u5668\u5fc5\u987b\u91cd\u590d\u8bf7\u6c42\u8fc7\u7a0b\uff0c\u83b7\u53d6\u6bcf\u4e2a\u5f15\u7528\u7684\u6587\u4ef6\u3002HTML\u3001\u56fe\u50cf\u3001\u7528\u4e8e\u6837\u5f0f\u7684\u7ea7\u8054\u6837\u5f0f\u8868 \uff08CSS\uff09 \u548c\u7528\u4e8e\u989d\u5916\u884c\u4e3a\u7684 JavaScript \u6587\u4ef6\u90fd\u4f7f\u7528\u5b8c\u5168\u76f8\u540c\u7684 HTTP \u8bf7\u6c42\u8fc7\u7a0b\u6765\u83b7\u53d6\u3002<\/p>\n<p>Pretty much all interactions that take place on the internet are a facade over this basic process. A basic web page may require only a few simple requests to render fully, whereas a large modern web page may take hundreds. At this writing, the Amazon .com home page (<a href=\"https:\/\/www.amazon.com\">https:\/\/www.amazon.com<\/a>) makes 410 requests, including requests for 4 CSS \ufb01les, 12 JavaScript \ufb01les, and 299 image \ufb01les!<\/p>\n<p>\u51e0\u4e4e\u6240\u6709\u53d1\u751f\u5728\u4e92\u8054\u7f51\u4e0a\u7684\u4ea4\u4e92\u90fd\u662f\u8fd9\u4e2a\u57fa\u672c\u8fc7\u7a0b\u7684\u5047\u8c61\u3002\u4e00\u4e2a\u57fa\u672c\u7684\u7f51\u9875\u53ef\u80fd\u53ea\u9700\u8981\u51e0\u4e2a\u7b80\u5355\u7684\u8bf7\u6c42\u5c31\u53ef\u4ee5\u5b8c\u5168\u5448\u73b0\uff0c\u800c\u4e00\u4e2a\u5927\u578b\u7684\u73b0\u4ee3\u7f51\u9875\u53ef\u80fd\u9700\u8981\u6570\u767e\u4e2a\u8bf7\u6c42\u3002\u5728\u64b0\u5199\u672c\u6587\u65f6\uff0cAmazon .com \u4e3b\u9875 \uff08<a href=\"https:\/\/www.amazon.com\">https:\/\/www.amazon.com<\/a>\uff09 \u53d1\u51fa\u4e86 410 \u4e2a\u8bf7\u6c42\uff0c\u5305\u62ec\u5bf9 4 \u4e2a CSS \u6587\u4ef6\u300112 \u4e2a JavaScript \u6587\u4ef6\u548c 299 \u4e2a\u56fe\u50cf\u6587\u4ef6\u7684\u8bf7\u6c42\uff01<\/p>\n<p>Now that you have a feel for the process, let\u2019s see how ASP.NET Core dynamically generates the response on the server.<\/p>\n<p>\u73b0\u5728\u60a8\u5df2\u7ecf\u4e86\u89e3\u4e86\u8be5\u8fc7\u7a0b\uff0c\u8ba9\u6211\u4eec\u770b\u770b ASP.NET Core \u5982\u4f55\u5728\u670d\u52a1\u5668\u4e0a\u52a8\u6001\u751f\u6210\u54cd\u5e94\u3002<\/p>\n<h4>1.4.2 How does ASP.NET Core process a request?\u200c<\/h4>\n<h4>1.4.2 ASP.NET Core \u5982\u4f55\u5904\u7406\u8bf7\u6c42\uff1f<\/h4>\n<p>When you build a web application with ASP.NET Core, browsers will still be using the same HTTP protocol as before to communicate with your application. ASP.NET Core itself encompasses everything that takes place on the server to handle a request, including verifying that the request is valid, handling login details, and generating HTML.<\/p>\n<p>\u5f53\u60a8\u4f7f\u7528 ASP.NET Core \u6784\u5efa Web \u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u6d4f\u89c8\u5668\u4ecd\u5c06\u4f7f\u7528\u4e0e\u4ee5\u524d\u76f8\u540c\u7684 HTTP \u534f\u8bae\u4e0e\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u901a\u4fe1\u3002ASP.NET Core \u672c\u8eab\u5305\u542b\u670d\u52a1\u5668\u4e0a\u4e3a\u5904\u7406\u8bf7\u6c42\u800c\u53d1\u751f\u7684\u6240\u6709\u4f5c\uff0c\u5305\u62ec\u9a8c\u8bc1\u8bf7\u6c42\u662f\u5426\u6709\u6548\u3001\u5904\u7406\u767b\u5f55\u8be6\u7ec6\u4fe1\u606f\u548c\u751f\u6210 HTML\u3002<\/p>\n<p>As with the generic web page example, the request process starts when a user\u2019s browser sends an HTTP request to the server, as shown in \ufb01gure 1.3.<\/p>\n<p>\u4e0e\u901a\u7528\u7f51\u9875\u793a\u4f8b\u4e00\u6837\uff0c\u5f53\u7528\u6237\u7684\u6d4f\u89c8\u5668\u5411\u670d\u52a1\u5668\u53d1\u9001 HTTP \u8bf7\u6c42\u65f6\uff0c\u8bf7\u6c42\u8fdb\u7a0b\u5f00\u59cb\uff0c\u5982\u56fe 1.3 \u6240\u793a\u3002<\/p>\n<p><img decoding=\"async\" src=\"\/images\/aspnetcoreinaction\/0103.png\" alt=\"alt text\" \/><\/p>\n<p>Figure 1.3 How an ASP.NET Core application processes a request. A request is received by the ASP.NET Core application, which runs a self-hosted web server. The web server processes the request and passes it to the body of the application, which generates a response and returns it to the web server. The web server sends this response to the browser.<\/p>\n<p>\u56fe 1.3 ASP.NET Core \u5e94\u7528\u7a0b\u5e8f\u5982\u4f55\u5904\u7406\u8bf7\u6c42\u3002\u8fd0\u884c\u81ea\u6258\u7ba1 Web \u670d\u52a1\u5668\u7684 ASP.NET Core \u5e94\u7528\u7a0b\u5e8f\u63a5\u6536\u8bf7\u6c42\u3002Web \u670d\u52a1\u5668\u5904\u7406\u8bf7\u6c42\u5e76\u5c06\u5176\u4f20\u9012\u7ed9\u5e94\u7528\u7a0b\u5e8f\u6b63\u6587\uff0c\u540e\u8005\u751f\u6210\u54cd\u5e94\u5e76\u5c06\u5176\u8fd4\u56de\u7ed9 Web \u670d\u52a1\u5668\u3002Web \u670d\u52a1\u5668\u5c06\u6b64\u54cd\u5e94\u53d1\u9001\u5230\u6d4f\u89c8\u5668\u3002<\/p>\n<p>The request is received from the network by your ASP.NET Core application. Every ASP.NET Core application has a built- in web server\u2014Kestrel, by default\u2014that is responsible for receiving raw requests and constructing an internal representation of the data, an HttpContext object, which the rest of the application can use.<\/p>\n<p>\u60a8\u7684 ASP.NET Core \u5e94\u7528\u7a0b\u5e8f\u4ece\u7f51\u7edc\u63a5\u6536\u8bf7\u6c42\u3002\u6bcf\u4e2a ASP.NET Core \u5e94\u7528\u7a0b\u5e8f\u90fd\u6709\u4e00\u4e2a\u5185\u7f6e\u7684 Web \u670d\u52a1\u5668\uff08\u9ed8\u8ba4\u4e3a Kestrel\uff09\uff0c\u8be5\u670d\u52a1\u5668\u8d1f\u8d23\u63a5\u6536\u539f\u59cb\u8bf7\u6c42\u5e76\u6784\u5efa\u6570\u636e\u7684\u5185\u90e8\u8868\u793a\u5f62\u5f0f\uff0c\u5373\u5e94\u7528\u7a0b\u5e8f\u7684\u5176\u4f59\u90e8\u5206\u53ef\u4ee5\u4f7f\u7528\u7684 HttpContext \u5bf9\u8c61\u3002<\/p>\n<p>Your application can use the details stored in HttpContext to generate an appropriate response to the request, which may be to generate some HTML, to return an \u201caccess denied\u201d message, or to send an email, all depending on your application\u2019s requirements.<\/p>\n<p>\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u4f7f\u7528\u5b58\u50a8\u5728 HttpContext \u4e2d\u7684\u8be6\u7ec6\u4fe1\u606f\u6765\u751f\u6210\u5bf9\u8bf7\u6c42\u7684\u9002\u5f53\u54cd\u5e94\uff0c\u8fd9\u53ef\u80fd\u662f\u751f\u6210\u4e00\u4e9b HTML\u3001\u8fd4\u56de\u201c\u62d2\u7edd\u8bbf\u95ee\u201d\u6d88\u606f\u6216\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\uff0c\u6240\u6709\u8fd9\u4e9b\u90fd\u53d6\u51b3\u4e8e\u5e94\u7528\u7a0b\u5e8f\u7684\u8981\u6c42\u3002<\/p>\n<p>When the application \ufb01nishes processing the request, it returns the response to the web server. The ASP.NET Core web server converts the representation to a raw HTTP response and sends it to the network, which forwards it to the user\u2019s browser.<\/p>\n<p>\u5f53\u5e94\u7528\u7a0b\u5e8f\u5b8c\u6210\u5904\u7406\u8bf7\u6c42\u65f6\uff0c\u5b83\u4f1a\u5c06\u54cd\u5e94\u8fd4\u56de\u7ed9 Web \u670d\u52a1\u5668\u3002ASP.NET Core Web \u670d\u52a1\u5668\u5c06\u8868\u793a\u5f62\u5f0f\u8f6c\u6362\u4e3a\u539f\u59cb HTTP \u54cd\u5e94\uff0c\u5e76\u5c06\u5176\u53d1\u9001\u5230\u7f51\u7edc\uff0c\u7f51\u7edc\u5c06\u5176\u8f6c\u53d1\u5230\u7528\u6237\u7684\u6d4f\u89c8\u5668\u3002<\/p>\n<p>To the user, this process appears to be the same as for the generic HTTP request shown in \ufb01gure 1.2: the user sent an HTTP request and received an HTTP response. All the di\ufb00erences are server-side, within your application.<\/p>\n<p>\u5bf9\u4e8e\u7528\u6237\u6765\u8bf4\uff0c\u6b64\u8fc7\u7a0b\u4f3c\u4e4e\u4e0e\u56fe 1.2 \u4e2d\u6240\u793a\u7684\u901a\u7528 HTTP \u8bf7\u6c42\u76f8\u540c\uff1a\u7528\u6237\u53d1\u9001\u4e86\u4e00\u4e2a HTTP \u8bf7\u6c42\u5e76\u6536\u5230\u4e86\u4e00\u4e2a HTTP \u54cd\u5e94\u3002\u6240\u6709\u5dee\u5f02\u90fd\u662f\u5728\u670d\u52a1\u5668\u7aef\u7684\u5e94\u7528\u7a0b\u5e8f\u4e2d\u3002<\/p>\n<p>You\u2019ve seen how requests and responses \ufb01nd their way to and from an ASP.NET Core application, but I haven\u2019t yet touched on how the response is generated. Throughout this book, we\u2019ll look at the components that make up a typical ASP.NET Core application and how they \ufb01t together. A lot goes into generating a response in ASP.NET Core, typically within a fraction of a second, but over the course of the book we\u2019ll step through an application slowly, covering each of the components in detail.\u200c<\/p>\n<p>\u60a8\u5df2\u7ecf\u4e86\u89e3\u4e86\u8bf7\u6c42\u548c\u54cd\u5e94\u5982\u4f55\u4e0e ASP.NET Core \u5e94\u7528\u7a0b\u5e8f\u4e4b\u95f4\u627e\u5230\u8fdb\u51fa\u65b9\u5f0f\uff0c\u4f46\u6211\u5c1a\u672a\u6d89\u53ca\u54cd\u5e94\u662f\u5982\u4f55\u751f\u6210\u7684\u3002\u5728\u672c\u4e66\u4e2d\uff0c\u6211\u4eec\u5c06\u4e86\u89e3\u6784\u6210\u5178\u578b ASP.NET Core \u5e94\u7528\u7a0b\u5e8f\u7684\u7ec4\u4ef6\uff0c\u4ee5\u53ca\u5b83\u4eec\u5982\u4f55\u7ec4\u5408\u5728\u4e00\u8d77\u3002\u5728 ASP.NET Core \u4e2d\u751f\u6210\u54cd\u5e94\u9700\u8981\u505a\u5f88\u591a\u5de5\u4f5c\uff0c\u901a\u5e38\u5728\u51e0\u5206\u4e4b\u4e00\u79d2\u5185\uff0c\u4f46\u5728\u672c\u4e66\u7684\u6574\u4e2a\u8fc7\u7a0b\u4e2d\u6211\u4eec\u5c06\u6162\u6162\u5730\u9010\u6b65\u5b8c\u6210\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\uff0c\u8be6\u7ec6\u4ecb\u7ecd\u6bcf\u4e2a\u7ec4\u4ef6\u3002<\/p>\n<h3>1.5 What you\u2019ll learn in this book\u200c<\/h3>\n<h3>1.5 \u60a8\u5c06\u5728\u672c\u4e66\u4e2d\u5b66\u5230\u4ec0\u4e48<\/h3>\n<p>This book takes you on an in-depth tour of the ASP.NET Core framework. To bene\ufb01t from the book, you should be familiar with C# or a similar object-oriented language. Basic familiarity with web concepts such as HTML and JavaScript will also be bene\ufb01cial. You\u2019ll learn the following:<\/p>\n<p>\u672c\u4e66\u5c06\u5e26\u60a8\u6df1\u5165\u6d4f\u89c8 ASP.NET Core \u6846\u67b6\u3002\u8981\u4ece\u672c\u4e66\u4e2d\u53d7\u76ca\uff0c\u60a8\u5e94\u8be5\u719f\u6089 C# \u6216\u7c7b\u4f3c\u7684\u9762\u5411\u5bf9\u8c61\u8bed\u8a00\u3002\u57fa\u672c\u719f\u6089 HTML \u548c JavaScript \u7b49 Web \u6982\u5ff5\u4e5f\u5c06\u662f\u6709\u76ca\u7684\u3002\u60a8\u5c06\u4e86\u89e3\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<ul>\n<li>\n<p>How to build HTTP API applications using minimal APIs<br \/>\n\u5982\u4f55\u4f7f\u7528\u6700\u5c11\u7684 API \u6784\u5efa HTTP API \u5e94\u7528\u7a0b\u5e8f<\/p>\n<\/li>\n<li>\n<p>How to create page-based applications with Razor Pages<br \/>\n\u5982\u4f55\u4f7f\u7528 Razor Pages \u521b\u5efa\u57fa\u4e8e\u9875\u9762\u7684\u5e94\u7528\u7a0b\u5e8f<\/p>\n<\/li>\n<li>\n<p>Key ASP.NET Core concepts such as model-binding, validation, and routing<br \/>\n\u5173\u952e ASP.NET \u6838\u5fc3\u6982\u5ff5\uff0c\u4f8b\u5982\u6a21\u578b\u7ed1\u5b9a\u3001\u9a8c\u8bc1\u548c\u8def\u7531<\/p>\n<\/li>\n<li>\n<p>How to generate HTML for web pages by using Razor syntax and Tag Helpers<br \/>\n\u5982\u4f55\u4f7f\u7528 Razor \u8bed\u6cd5\u548c\u6807\u8bb0\u5e2e\u52a9\u7a0b\u5e8f\u4e3a\u7f51\u9875\u751f\u6210 HTML<\/p>\n<\/li>\n<li>\n<p>How to use features such as dependency injection, con\ufb01guration, and logging as your applications grow more complex<br \/>\n\u5982\u4f55\u5728\u5e94\u7528\u7a0b\u5e8f\u53d8\u5f97\u8d8a\u6765\u8d8a\u590d\u6742\u65f6\u4f7f\u7528\u4f9d\u8d56\u9879\u6ce8\u5165\u3001\u914d\u7f6e\u548c\u65e5\u5fd7\u8bb0\u5f55\u7b49\u529f\u80fd<\/p>\n<\/li>\n<li>\n<p>How to protect your application by using security best practices<br \/>\n\u5982\u4f55\u4f7f\u7528\u5b89\u5168\u6700\u4f73\u5b9e\u8df5\u4fdd\u62a4\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f<\/p>\n<\/li>\n<\/ul>\n<p>Throughout the book we\u2019ll use a variety of examples to learn and explore concepts. The examples are generally small and self-contained so that we can focus on a single feature at a time.<\/p>\n<p>\u5728\u6574\u672c\u4e66\u4e2d\uff0c\u6211\u4eec\u5c06\u4f7f\u7528\u5404\u79cd\u793a\u4f8b\u6765\u5b66\u4e60\u548c\u63a2\u7d22\u6982\u5ff5\u3002\u8fd9\u4e9b\u793a\u4f8b\u901a\u5e38\u5f88\u5c0f\uff0c\u5e76\u4e14\u81ea\u5305\u542b\uff0c\u4ee5\u4fbf\u6211\u4eec\u53ef\u4ee5\u4e00\u6b21\u4e13\u6ce8\u4e8e\u4e00\u4e2a\u529f\u80fd\u3002<\/p>\n<p>I\u2019ll be using Visual Studio for most of the examples in this book, but you\u2019ll be able to follow along using your favorite editor or integrated development environment (IDE).<\/p>\n<p>\u5bf9\u4e8e\u672c\u4e66\u4e2d\u7684\u5927\u591a\u6570\u793a\u4f8b\uff0c\u6211\u5c06\u4f7f\u7528 Visual Studio\uff0c\u4f46\u60a8\u5c06\u80fd\u591f\u4f7f\u7528\u60a8\u6700\u559c\u6b22\u7684\u7f16\u8f91\u5668\u6216\u96c6\u6210\u5f00\u53d1\u73af\u5883 \uff08IDE\uff09 \u6765\u5b66\u4e60\u3002<\/p>\n<p>Appendix A includes details on setting up your editor or IDE and installing the .NET 7 software development kit (SDK).<\/p>\n<p>\u9644\u5f55 A \u5305\u62ec\u6709\u5173\u8bbe\u7f6e\u7f16\u8f91\u5668\u6216 IDE \u4ee5\u53ca\u5b89\u88c5 .NET 7 \u8f6f\u4ef6\u5f00\u53d1\u5de5\u5177\u5305 \uff08SDK\uff09 \u7684\u8be6\u7ec6\u4fe1\u606f\u3002<\/p>\n<p>Even though the examples in this book show Windows tools, everything you see can be achieved equally well on the Linux or Mac platform.<\/p>\n<p>\u5c3d\u7ba1\u672c\u4e66\u4e2d\u7684\u793a\u4f8b\u5c55\u793a\u4e86 Windows \u5de5\u5177\uff0c\u4f46\u60a8\u6240\u770b\u5230\u7684\u4e00\u5207\u90fd\u53ef\u4ee5\u5728 Linux \u6216 Mac \u5e73\u53f0\u4e0a\u540c\u6837\u51fa\u8272\u5730\u5b9e\u73b0\u3002<\/p>\n<p><strong>TIP<\/strong> You can install .NET 7 from <a href=\"https:\/\/dotnet.microsoft.com\/download\">https:\/\/dotnet.microsoft.com\/download<\/a>. Appendix A contains further details on con\ufb01guring your development environment to work with ASP.NET Core and .NET 7.<\/p>\n<p><strong>\u63d0\u793a<\/strong> \u60a8\u53ef\u4ee5\u4ece <a href=\"https:\/\/dotnet.microsoft.com\/download\">https:\/\/dotnet.microsoft.com\/download<\/a> \u5b89\u88c5 .NET 7\u3002\u9644\u5f55 A \u5305\u542b\u6709\u5173\u914d\u7f6e\u5f00\u53d1\u73af\u5883\u4ee5\u4f7f\u7528 ASP.NET Core \u548c .NET 7 \u7684\u66f4\u591a\u8be6\u7ec6\u4fe1\u606f\u3002<\/p>\n<p>In chapter 2, we\u2019ll look in greater depth at the types of applications you can create with ASP.NET Core. We\u2019ll also explore its advantages over the older ASP.NET and .NET Framework platforms.<\/p>\n<p>\u5728\u7b2c 2 \u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u66f4\u6df1\u5165\u5730\u4e86\u89e3\u60a8\u53ef\u4ee5\u4f7f\u7528 ASP.NET Core \u521b\u5efa\u7684\u5e94\u7528\u7a0b\u5e8f\u7c7b\u578b\u3002\u6211\u4eec\u8fd8\u5c06\u63a2\u8ba8\u5b83\u4e0e\u65e7\u7248 ASP.NET \u548c .NET Framework \u5e73\u53f0\u76f8\u6bd4\u7684\u4f18\u52bf\u3002<\/p>\n<h2>Summary<\/h2>\n<h2>\u603b\u7ed3<\/h2>\n<p>ASP.NET Core is a cross-platform, open-source, high-performance web framework.<br \/>\nASP.NET Core \u662f\u4e00\u4e2a\u8de8\u5e73\u53f0\u3001\u5f00\u6e90\u3001\u9ad8\u6027\u80fd\u7684 Web \u6846\u67b6\u3002<br \/>\nASP.NET Core runs on .NET, previously called .NET Core.<br \/>\nASP.NET Core \u5728 .NET\uff08\u4ee5\u524d\u79f0\u4e3a .NET Core\uff09\u4e0a\u8fd0\u884c\u3002<\/p>\n<p>You can use Razor Pages or MVC controllers to build server-rendered, page-based web applications.<br \/>\n\u60a8\u53ef\u4ee5\u4f7f\u7528 Razor Pages \u6216 MVC \u63a7\u5236\u5668\u6765\u6784\u5efa\u670d\u52a1\u5668\u5448\u73b0\u7684\u3001\u57fa\u4e8e\u9875\u9762\u7684 Web \u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>You can use minimal APIs or web APIs to build RESTful or HTTP APIs.<br \/>\n\u60a8\u53ef\u4ee5\u4f7f\u7528\u6700\u5c11\u7684 API \u6216 Web API \u6765\u6784\u5efa RESTful \u6216 HTTP API\u3002<\/p>\n<p>You can use gRPC to build highly e\ufb03cient server-to- server RPC applications.<br \/>\n\u60a8\u53ef\u4ee5\u4f7f\u7528 gRPC \u6784\u5efa\u9ad8\u6548\u7684\u670d\u52a1\u5668\u5230\u670d\u52a1\u5668 RPC \u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>You can use Blazor WebAssembly to build client- side applications that run in the browser and Blazor Server to build stateful, server-rendered applications that send UI updates via a WebSocket connection.<br \/>\n\u53ef\u4ee5\u4f7f\u7528 Blazor WebAssembly \u6784\u5efa\u5728\u6d4f\u89c8\u5668\u4e2d\u8fd0\u884c\u7684\u5ba2\u6237\u7aef\u5e94\u7528\u7a0b\u5e8f\uff0c\u4f7f\u7528 Blazor Server \u6784\u5efa\u6709\u72b6\u6001\u7684\u670d\u52a1\u5668\u5448\u73b0\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u8fd9\u4e9b\u5e94\u7528\u7a0b\u5e8f\u901a\u8fc7 WebSocket \u8fde\u63a5\u53d1\u9001 UI \u66f4\u65b0\u3002<\/p>\n<p>Microsoft recommends ASP.NET Core and .NET 7 or later for all new web development over the legacy ASP.NET and .NET Framework platforms.<br \/>\nMicrosoft \u5efa\u8bae ASP.NET Core \u548c .NET 7 \u6216\u66f4\u9ad8\u7248\u672c\uff0c\u4ee5\u4fbf\u5728\u65e7\u7248 ASP.NET \u548c .NET Framework \u5e73\u53f0\u4e0a\u8fdb\u884c\u6240\u6709\u65b0\u7684 Web \u5f00\u53d1\u3002<\/p>\n<p>Fetching a web page involves sending an HTTP request and receiving an HTTP response.<br \/>\n\u83b7\u53d6\u7f51\u9875\u6d89\u53ca\u53d1\u9001 HTTP \u8bf7\u6c42\u548c\u63a5\u6536 HTTP \u54cd\u5e94\u3002<\/p>\n<p>ASP.NET Core allows you to build responses to a given request dynamically.<br \/>\nASP.NET Core \u5141\u8bb8\u60a8\u52a8\u6001\u6784\u5efa\u5bf9\u7ed9\u5b9a\u8bf7\u6c42\u7684\u54cd\u5e94\u3002<\/p>\n<p>An ASP.NET Core application contains a web server, which serves as the entry point for a request.<br \/>\nASP.NET Core \u5e94\u7528\u7a0b\u5e8f\u5305\u542b\u4e00\u4e2a Web \u670d\u52a1\u5668\uff0c\u8be5\u670d\u52a1\u5668\u7528\u4f5c\u8bf7\u6c42\u7684\u5165\u53e3\u70b9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ASP.NET Core in Action 1 Getting started with ASP.NET Core 1 Getting started with ASP.NET Core 1 ASP.NET Core \u5165\u95e8 This chapter covers \u672c\u7ae0\u6db5\u76d6 What is ASP.NET Core? \u4ec0\u4e48\u662f ASP.NET Core\uff1f Things you can build with ASP.NET Core \u60a8\u53ef\u4ee5\u4f7f\u7528 ASP.NET Core \u6784\u5efa\u7684\u5185\u5bb9 How ASP.NET Core works ASP.NET Core \u7684\u5de5\u4f5c\u539f\u7406 Choosing to learn and develop with [&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-568","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\/568","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=568"}],"version-history":[{"count":0,"href":"https:\/\/diji.net\/index.php?rest_route=\/wp\/v2\/posts\/568\/revisions"}],"wp:attachment":[{"href":"https:\/\/diji.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=568"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/diji.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=568"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/diji.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=568"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}