{"id":496,"date":"2023-10-16T00:35:34","date_gmt":"2023-10-16T07:35:34","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/?p=496"},"modified":"2023-10-16T00:35:34","modified_gmt":"2023-10-16T07:35:34","slug":"net-8-%e4%b8%ad%e7%9a%84%e8%b0%83%e8%af%95%e5%a2%9e%e5%bc%ba%e5%8a%9f%e8%83%bd","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/net-8-%e4%b8%ad%e7%9a%84%e8%b0%83%e8%af%95%e5%a2%9e%e5%bc%ba%e5%8a%9f%e8%83%bd\/","title":{"rendered":".NET 8 \u4e2d\u7684\u8c03\u8bd5\u589e\u5f3a\u529f\u80fd"},"content":{"rendered":"<p style=\"text-align: center;\">\u672c\u7bc7\u7ffb\u8bd1\u4e8eJames Newton-King\u7684<a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/debugging-enhancements-in-dotnet-8\/\">Debugging Enhancements in .NET 8<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>\u5f00\u53d1\u4eba\u5458\u559c\u6b22 .NET \u5f3a\u5927\u4e14\u7528\u6237\u53cb\u597d\u7684\u8c03\u8bd5\u4f53\u9a8c\u3002\u60a8\u53ef\u4ee5\u5728\u60a8\u9009\u62e9\u7684 IDE \u4e2d\u8bbe\u7f6e\u65ad\u70b9\uff0c\u542f\u52a8\u5df2\u7ecf\u9644\u52a0\u4e0a\u8c03\u8bd5\u5668\u7684\u7a0b\u5e8f\uff0c\u9010\u6b65\u6267\u884c\u4ee3\u7801\u5e76\u67e5\u770b .NET \u5e94\u7528\u7a0b\u5e8f\u7684\u72b6\u6001\u3002<\/p>\n<p>\u5728 .NET 8 \u4e2d\uff0c\u6211\u4eec\u81f4\u529b\u4e8e\u6539\u5584 .NET \u5e94\u7528\u4e2d\u5e38\u7528\u7c7b\u578b\u7684\u8c03\u8bd5\u4f53\u9a8c\u3002\u8fd9\u4e9b\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><span style=\"color: #ff0000;\">HttpContext<\/span>\u4e0e\u5176\u4f19\u4f34<\/li>\n<li><span style=\"color: #ff0000;\">WebApplication<\/span><\/li>\n<li>MVC and Razor Pages<\/li>\n<li>gRPC<\/li>\n<li>\u7aef\u70b9\u5143\u6570\u636e<\/li>\n<li>\u65e5\u5fd7<\/li>\n<li>\u914d\u7f6e<\/li>\n<\/ul>\n<p>\u60a8\u4e0d\u9700\u8981\u6df1\u5165\u4e86\u89e3\u8fd9\u4e9b\u7c7b\u578b\u7684\u5185\u90e8\u7ed3\u6784\u5c31\u53ef\u4ee5\u627e\u5230\u6709\u5173\u5e94\u7528\u7a0b\u5e8f\u7684\u4fe1\u606f\u3002\u6211\u4eec\u4e3a\u5e38\u7528\u7684 .NET \u7c7b\u578b\u6dfb\u52a0\u4e86<a href=\"https:\/\/learn.microsoft.com\/en-us\/visualstudio\/debugger\/using-the-debuggerdisplay-attribute?view=vs-2022\">\u81ea\u5b9a\u4e49\u8c03\u8bd5\u5c5e\u6027<\/a>\u7684\u529f\u80fd\u6765\u663e\u793a\u8c03\u8bd5\u6458\u8981\u4ee5\u53ca\u63d0\u4f9b\u7b80\u5316\u7684\u8c03\u8bd5\u4ee3\u7406\u3002<\/p>\n<h3><strong>HttpContext\u4e0e\u5176\u4f19\u4f34<\/strong><\/h3>\n<p><span style=\"color: #ff0000;\">HttpContext<\/span>\u3001<span style=\"color: #ff0000;\">HttpRequest<\/span> \u548c <span style=\"color: #ff0000;\">HttpResponse<\/span> \u5bf9\u4e8e\u4f7f\u7528ASP.NET Core\u6784\u5efaWeb\u5e94\u7528\u7a0b\u5e8f\u7684\u5f00\u53d1\u4eba\u5458\u6765\u8bf4\u5e94\u8be5\u662f\u975e\u5e38\u719f\u6089\u7684\u3002\u5982\u679c\u60a8\u60f3\u67e5\u770b HTTP \u8bf7\u6c42\u7684\u72b6\u6001\uff0c\u5c31\u80af\u5b9a\u9700\u8981\u8c03\u8bd5\u8fd9\u4e9b\u7c7b\u578b\u3002<\/p>\n<p>\u6211\u4eec\u5ba1\u67e5\u4e86 ASP.NET Core \u7684 HTTP \u7c7b\u578b\u7684\u5c5e\u6027\uff0c\u4ee5\u4fbf\u5b83\u4eec\u66f4\u5bb9\u6613\u4e0e\u8c03\u8bd5\u5668\u4e00\u8d77\u4f7f\u7528\u3002\u67e5\u770b\u8bf7\u6c42\u548c\u54cd\u5e94\u503c\uff08\u4f8b\u5982header\u3001cookie\u3001\u67e5\u8be2\u5b57\u7b26\u4e32\u548c\u8868\u5355\u503c\uff09\u53d8\u5f97\u66f4\u52a0\u5bb9\u6613\uff0c\u73b0\u5728<span style=\"color: #ff0000;\">HttpRequest<\/span>\u548c<span style=\"color: #ff0000;\">HttpResponse<\/span>\u8fd8\u663e\u793a\u4e86\u7528\u6237\u53cb\u597d\u7684\u7c7b\u578b\u6458\u8981\uff0c\u50cfHTTP\u8bf7\u6c42URL\u6216HTTP\u54cd\u5e94\u72b6\u6001\u7801\u4e4b\u7c7b\u7684\u5173\u952e\u4fe1\u606f\u5373\u523b\u53ef\u89c1\u3002<\/p>\n<p>\u4e0b\u9762\u7684\u5c4f\u5e55\u622a\u56fe\u663e\u793a\u4e86\u5bf9<span style=\"color: #ff0000;\">HttpContext<\/span>\u76f8\u5173\u7c7b\u578b\u7684\u6539\u8fdb\uff1a<\/p>\n<p><strong>.NET 7<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2023\/06\/httpcontext-debugging-before.png\" alt=\"ASP.NET Core debugging before\" \/><\/p>\n<p><strong>.NET 8<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2023\/06\/httpcontext-debugging-after.png\" alt=\"ASP.NET Core debugging after\" \/><\/p>\n<p>\u76f8\u6bd4\u4e4b\u524d\u597d\u4e86\u5f88\u591a\uff01\u5c3d\u7ba1\u9690\u85cf\u4e86\u4e00\u4e9b\u6570\u636e\uff0c\u4f46\u6ca1\u6709\u4e22\u5931\u4efb\u4f55\u5185\u5bb9\u3002 \u60a8\u53ef\u4ee5\u9009\u62e9Raw View\u4ee5\u67e5\u770b\u6240\u6709\u5b57\u6bb5\u548c\u5c5e\u6027\u3002<\/p>\n<h3><strong>WebApplication<\/strong><\/h3>\n<p><span style=\"color: #ff0000;\">WebApplication<\/span> \u662f\u5728 <span style=\"color: #ff0000;\">Program.cs<\/span> \u4e2d\u914d\u7f6e\u548c\u542f\u52a8 ASP.NET Core \u5e94\u7528\u7a0b\u5e8f\u7684\u9ed8\u8ba4\u65b9\u5f0f\u3002 \u66f4\u65b0\u540e\u7684<span style=\"color: #ff0000;\">WebApplication<\/span> \u4f1a\u663e\u793a\u91cd\u8981\u4fe1\u606f\uff0c\u4f8b\u5982 IDE \u8c03\u8bd5\u5668\u4e2d\u914d\u7f6e\u7684\u7aef\u70b9\u3001\u4e2d\u95f4\u4ef6\u548c <span style=\"color: #ff0000;\">IConfiguration<\/span> \u503c\u3002<\/p>\n<p><strong>.NET 7<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2023\/09\/webapplication-debugging-before.png\" alt=\"WebApplication debugging before\" \/><\/p>\n<p><strong>.NET 8<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2023\/09\/webapplication-debugging-after.png\" alt=\"WebApplication debugging after\" \/><\/p>\n<p>\u6211\u4eec\u5bf9.NET Generic Host\u8fdb\u884c\u4e86\u7c7b\u4f3c\u7684\u6539\u8fdb\u3002 Generic Host \u7528\u4e8e\u6258\u7ba1\u6ca1\u6709 HTTP \u7aef\u70b9\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u4f8b\u5982 Unix daemons \u548cWindows Services\u3002<\/p>\n<h3><strong>MVC and Razor Pages<\/strong><\/h3>\n<p>ASP.NET Core MVC \u548c Razor Pages \u662f\u6784\u5efa Web \u5e94\u7528\u7a0b\u5e8f\u7684\u6d41\u884c\u6846\u67b6\u3002\u63a7\u5236\u5668\u3001\u89c6\u56fe\u548c Razor Pages\u5728 .NET 8 \u4e2d\u7684\u8c03\u8bd5\u83b7\u5f97\u4e86\u6539\u8fdb\u3002<\/p>\n<p>\u5728\u8c03\u8bd5\u8fd9\u4e9b\u6846\u67b6\u65f6\uff0c\u6211\u4eec\u53d1\u73b0\u4e86\u5f88\u591a\u989d\u5916\u7684\u4fe1\u606f\u3002\u4f17\u591a\u7684\u7c7b\u578b\u8ba9\u4eba\u611f\u89c9\u5f88\u6df7\u4e71\u3002\u5728 .NET 8 \u4e2d\uff0c\u6211\u4eec\u5ba1\u67e5\u4e86\u6bcf\u4e00\u79cd\u7c7b\u578b\u5e76\u626a\u5fc3\u81ea\u95ee\uff1a\u201c\u8fd9\u4f1a\u7ed9\u8c03\u8bd5\u5e26\u6765\u5feb\u4e50\u5417\uff1f\u201d\u73b0\u5728\uff0c\u5927\u591a\u6570 MVC \u548c Razor \u7c7b\u578b\u90fd\u53ef\u4ee5\u66f4\u597d\u5730\u8fdb\u884c\u8c03\u8bd5\uff0c\u5e76\u4e14\u9690\u85cf\u4e86\u975e\u5fc5\u8981\u7c7b\u578b\u3002\u4e0b\u9762\u7684\u5c4f\u5e55\u622a\u56fe\u5c55\u793a\u4e86 MVC \u63a7\u5236\u5668\u7684\u6539\u8fdb\uff1a<\/p>\n<p><strong>.NET 7<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2023\/09\/controller-debugging-before.png\" alt=\"Controller debugging before\" \/><\/p>\n<p><strong>.NET 8<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2023\/09\/controller-debugging-after.png\" alt=\"Controller debugging after\" \/><\/p>\n<p>\u76f8\u4fe1\u8fd9\u79cd\u6574\u7406\u540e\u7684\u8f93\u51fa\u66f4\u5bb9\u6613\u5904\u7406\u3002<\/p>\n<h3><strong>gRPC<\/strong><\/h3>\n<p>gRPC \u662f\u4e00\u4e2a\u7528\u4e8e\u6784\u5efa RPC \u670d\u52a1\u7684\u9ad8\u6027\u80fd\u5e93\u3002 \u6700\u65b0\u7248\u672c\u7684 gRPC \u8ba9\u60a8\u53ef\u4ee5\u66f4\u5bb9\u6613\u5730\u8c03\u8bd5\u6765\u81ea\u5ba2\u6237\u7aef\u7684 gRPC \u8c03\u7528\u3002 \u73b0\u5728\u7684gRPC \u8c03\u7528\u5305\u542b\u6709\u5173\u5176\u65b9\u6cd5\u3001\u72b6\u6001\u3001\u54cd\u5e94\u6807\u5934\u548c\u5c3e\u90e8\u7684\u4fe1\u606f\u3002 \u6709\u5173\u8bf7\u6c42\/\u54cd\u5e94\u548c\u6d41\u5f0f\u4f20\u8f93\u7684\u5176\u4ed6\u4fe1\u606f\u53d6\u51b3\u4e8e <a href=\"https:\/\/learn.microsoft.com\/en-us\/aspnet\/core\/grpc\/client?view=aspnetcore-7.0#make-grpc-calls\">gRPC \u8c03\u7528\u7c7b\u578b<\/a>\u3002 \u4e0b\u9762\u7684\u793a\u4f8b\u662f\u4e00\u5143\u8c03\u7528\u3002<\/p>\n<p><strong>grpc-dotnet 2.55.0<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2023\/09\/grpc-debugging-before.png\" alt=\"gRPC debugging before\" \/><\/p>\n<p><strong>grpc-dotnet 2.56.0<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2023\/09\/grpc-debugging-after.png\" alt=\"gRPC debugging after\" \/><\/p>\n<p>\u60a8\u53ef\u4ee5\u901a\u8fc7\u5c06 <a href=\"https:\/\/www.nuget.org\/packages\/Grpc.Net.Client\">Grpc.Net.Client<\/a> \u66f4\u65b0\u5230 2.56.0 \u6216\u66f4\u9ad8\u7248\u672c\u6765\u4f53\u9a8c\u8fd9\u4e9b\u6539\u52a8\u3002<\/p>\n<p><strong>\u7aef\u70b9\u5143\u6570\u636e<\/strong><\/p>\n<p>\u7aef\u70b9\u662f ASP.NET Core \u7684\u6838\u5fc3\u6982\u5ff5\u3002 \u7aef\u70b9\u4ee3\u8868\u53ef\u6267\u884c\u7684\u8bf7\u6c42\u5904\u7406\u4ee3\u7801\u3002\u5f53\u5e94\u7528\u7a0b\u5e8f\u542f\u52a8\u65f6\uff0c\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u5b9a\u4e49\u7684\u7aef\u70b9\u88ab\u6ce8\u518c\u4e3a\u8def\u7531\u3002 \u7136\u540e\uff0c\u5f53 HTTP \u8bf7\u6c42\u8fdb\u5165\u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u8def\u7531\u5c06\u8bf7\u6c42\u5339\u914d\u5230\u7aef\u70b9\u3002 \u7aef\u70b9\u7684\u793a\u4f8b\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>MVC actions<\/li>\n<li>Razor Pages<\/li>\n<li>Minimal APIs<\/li>\n<li>gRPC methods<\/li>\n<\/ul>\n<p>\u7aef\u70b9\u53ef\u4ee5\u6709\u5143\u6570\u636e\uff0c\u5143\u6570\u636e\u63a7\u5236\u8bf7\u6c42\u7684\u6267\u884c\u65b9\u5f0f\u3002 \u4f8b\u5982\uff0cAPI \u4e0a\u7684 <span style=\"color: #ff0000;\">[Authorize]<\/span> \u5c5e\u6027\u4fdd\u5b58\u4e3a\u7aef\u70b9\u5143\u6570\u636e\uff0c\u7136\u540e<span style=\"color: #ff0000;\">AuthorizationMiddleware<\/span> \u5728\u5904\u7406\u8bf7\u6c42\u65f6\u4f7f\u7528\u5b83\u3002<\/p>\n<p>\u5728 .NET 8 \u4e2d\uff0c\u8c03\u8bd5\u6587\u672c\u5df2\u7ecf\u6dfb\u52a0\u5230\u516c\u5171\u5143\u6570\u636e\u4e2d\u3002 \u4e0b\u9762\u7684\u5c4f\u5e55\u622a\u56fe\u6bd4\u8f83\u4e86 .NET 7 \u548c .NET 8 \u4e2d\u7684 <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/api\/microsoft.aspnetcore.http.endpoint.metadata?view=aspnetcore-7.0\">Endpoint.Metadata<\/a> \u8c03\u8bd5\u3002\u66f4\u5bb9\u6613\u7406\u89e3\u914d\u7f6e\u4e86\u54ea\u4e9b\u5143\u6570\u636e\u4ee5\u53ca\u5982\u4f55\u5904\u7406\u4e0e\u7aef\u70b9\u5339\u914d\u7684\u8bf7\u6c42\u3002<\/p>\n<p><strong>.NET 7<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2023\/09\/metadata-debugging-before.png\" alt=\"Metadata debugging before\" \/><\/p>\n<p><strong>.NET 8<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2023\/09\/metadata-debugging-after.png\" alt=\"Metadata debugging after\" \/><\/p>\n<h3><strong>\u65e5\u5fd7<\/strong><\/h3>\n<p><a href=\"https:\/\/learn.microsoft.com\/en-us\/aspnet\/core\/fundamentals\/logging\/?view=aspnetcore-7.0\">Microsoft.Extensions.Logging<\/a> \u662f .NET \u5e94\u7528\u7a0b\u5e8f\u5f00\u53d1\u4e2d\u6d41\u884c\u7684\u65e5\u5fd7\u8bb0\u5f55\u5e93\uff0c\u5728\u6574\u4e2a ASP.NET Core \u4e2d\u4f7f\u7528\u3002 \u5e94\u7528\u7a0b\u5e8f\u4f7f\u7528 <span style=\"color: #ff0000;\">ILogger<\/span> \u8f93\u51fa\u7ed3\u6784\u5316\u65e5\u5fd7\u3002<\/p>\n<p>ILogger \u4ece\u6765\u5c31\u4e0d\u662f\u4e3a\u8c03\u8bd5\u800c\u8bbe\u8ba1\u7684\u3002 \u8fd9\u662f\u4e00\u4e2a\u7528\u4e8e\u5199\u5165\u65e5\u5fd7\u7684\u7b80\u5355\u63a5\u53e3\u3002 \u5728\u8c03\u8bd5 <span style=\"color: #ff0000;\">ILogger<\/span> \u5b9e\u4f8b\u65f6\uff0c\u8fd9\u79cd\u8bbe\u8ba1\u9009\u62e9\u662f\u663e\u800c\u6613\u89c1\u7684\u3002 \u5b83\u663e\u793a\u4e86\u4e3a\u6027\u80fd\u800c\u8bbe\u8ba1\u7684\u96be\u4ee5\u7406\u89e3\u7684\u6570\u636e\u7ed3\u6784\u3002<\/p>\n<p>\u5728 .NET 8 \u4e2d\uff0c\u53ef\u4ee5\u66f4\u5bb9\u6613\u5730\u4e86\u89e3\u662f\u5426\u542f\u7528\u4e86\u65e5\u5fd7\u8bb0\u5f55\u4ee5\u53ca\u914d\u7f6e\u4e86\u54ea\u4e9b\u65e5\u5fd7\u8bb0\u5f55\u63d0\u4f9b\u7a0b\u5e8f\u3002 <span style=\"color: #ff0000;\">ILogger<\/span> \u663e\u793a\u4e86\u4e00\u4e2a\u7528\u6237\u53cb\u597d\u7684\u6709\u7528\u4fe1\u606f\u5217\u8868\uff0c\u4f8b\u5982\u5176\u540d\u79f0\u3001\u914d\u7f6e\u7684\u65e5\u5fd7\u7ea7\u522b\u3001\u662f\u5426\u542f\u7528\u4ee5\u53ca\u914d\u7f6e\u7684\u65e5\u5fd7\u8bb0\u5f55\u63d0\u4f9b\u7a0b\u5e8f\u3002<\/p>\n<p><strong>.NET 7<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2023\/09\/logging-debugging-before.png\" alt=\"Logging debugging before\" \/><\/p>\n<p><strong>.NET 8<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2023\/09\/logging-debugging-after.png\" alt=\"Logging debugging after\" \/><\/p>\n<h3><strong>\u914d\u7f6e<\/strong><\/h3>\n<p><a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/core\/extensions\/configuration\">Microsoft.Extensions.Configuration<\/a> \u662f.NET\u5e94\u7528\u7a0b\u5e8f\u548c\u5e93\u4f7f\u7528\u7684\u914d\u7f6e\u62bd\u8c61\u5c42\u3002 <span style=\"color: #ff0000;\">IConfiguration<\/span> \u53ef\u4ee5\u4ece\u914d\u7f6e\u63d0\u4f9b\u7a0b\u5e8f\u52a0\u8f7d\u503c\uff0c\u4f8b\u5982 JSON \u6587\u4ef6\u3001\u73af\u5883\u53d8\u91cf\u3001Azure Key Value\u6216\u7b2c\u4e09\u65b9\u63d0\u4f9b\u7a0b\u5e8f\u3002<\/p>\n<p>\u4f7f\u7528\u914d\u7f6e\u7684\u793a\u4f8b\u4f4d\u4e8e ASP.NET Core \u6a21\u677f\u4e2d\u3002 \u7531\u6a21\u677f\u6dfb\u52a0\u7684 appsettings.json \u6587\u4ef6\u914d\u7f6e\u5e94\u7528\u7a0b\u5e8f\u7684\u65e5\u5fd7\u7ea7\u522b\uff1a<\/p>\n<pre class=\" prettyprinted\" tabindex=\"0\"><code class=\"language-json prettyprinted\"><span class=\"pun\">{<\/span>\r\n  <span class=\"str\">\"Logging\"<\/span><span class=\"pun\">:<\/span> <span class=\"pun\">{<\/span>\r\n    <span class=\"str\">\"LogLevel\"<\/span><span class=\"pun\">:<\/span> <span class=\"pun\">{<\/span>\r\n      <span class=\"str\">\"Default\"<\/span><span class=\"pun\">:<\/span> <span class=\"str\">\"Information\"<\/span>\r\n    <span class=\"pun\">}<\/span>\r\n  <span class=\"pun\">}<\/span>\r\n<span class=\"pun\">}<\/span><\/code><\/pre>\n<p>\u5728 .NET 8 \u4e4b\u524d\uff0c\u5f04\u6e05\u695a\u5e94\u7528\u7a0b\u5e8f\u7684\u914d\u7f6e\u503c\u53ef\u80fd\u975e\u5e38\u56f0\u96be\u3002 \u914d\u7f6e\u652f\u6301\u591a\u4e2a\u63d0\u4f9b\u7a0b\u5e8f\uff0c\u63d0\u4f9b\u7a0b\u5e8f\u53ef\u4ee5\u4f18\u5148\u4e8e\u5176\u4ed6\u63d0\u4f9b\u7684\u7a0b\u5e8f\u3002 \u4f8b\u5982\uff0c\u867d\u7136\u9ed8\u8ba4\u59cb\u7ec8\u4f7f\u7528 <span style=\"color: #ff0000;\">appsettings.json<\/span> \u4e2d\u7684\u503c\uff0c\u4f46\u5b83\u4eec\u4f1a\u88ab <span style=\"color: #ff0000;\">appsettings.Development.json<\/span> \u6216 <span style=\"color: #ff0000;\">appsettings.Production.json<\/span> \u6709\u6761\u4ef6\u5730\u8986\u76d6\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u5e94\u7528\u7a0b\u5e8f\u7684\u53d1\u5e03\u65b9\u5f0f\u3002<\/p>\n<p>\u5728 .NET 8 \u4e2d\uff0c\u73b0\u5728\u8c03\u8bd5 <span style=\"color: #ff0000;\">IConfiguration<\/span>\u4f1a\u663e\u793a\u4e00\u4e2a\u5305\u542b\u6240\u6709\u914d\u7f6e\u952e\u548c\u503c\u7684\u7b80\u5355\u5217\u8868\u3002\u4f18\u5148\u7ea7\u5df2\u8ba1\u7b97\u8fc7\u4e86\uff0c\u56e0\u6b64\u60a8\u770b\u5230\u7684\u914d\u7f6e\u503c\u5c31\u662f\u5e94\u7528\u7a0b\u5e8f\u5c06\u8981\u4f7f\u7528\u7684\u503c\u3002<\/p>\n<p><strong>.NET 7<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2023\/09\/configuration-debugging-before.png\" alt=\"Configuration debugging before\" \/><\/p>\n<p><strong>.NET 8<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2023\/09\/configuration-debugging-after.png\" alt=\"Configuration debugging after\" \/><\/p>\n<h3><strong>\u66f4\u591a\u4fe1\u606f<\/strong><\/h3>\n<p>\u6709\u592a\u591a\u7684\u6539\u8fdb\uff0c\u65e0\u6cd5\u4e00\u4e00\u8be6\u8ff0\u4ee5\u53ca\u5217\u51fa\u5b83\u4eec\u3002\u4f46\u9884\u8ba1 .NET 8 \u4e2d\u7684\u8c03\u8bd5\u5668\u53ef\u89c6\u5316\u4f1a\u6709\u66f4\u591a\u6539\u8fdb\uff1a<\/p>\n<ul>\n<li>\u4f9d\u8d56\u6ce8\u5165<\/li>\n<li><span style=\"color: #ff0000;\">ClaimsPrincipal<\/span>\u548c<span style=\"color: #ff0000;\">ClaimsIdentity<\/span><\/li>\n<li><span style=\"color: #ff0000;\">StringValues<\/span>\u548c<span style=\"color: #ff0000;\">StringSegment<\/span><\/li>\n<li><span style=\"color: #ff0000;\">HostString<\/span>, <span style=\"color: #ff0000;\">PathString<\/span>,<span style=\"color: #ff0000;\">QueryString<\/span>\u548c<span style=\"color: #ff0000;\">FragmentString<\/span><\/li>\n<li>HTTP \u6807\u5934\u96c6\u5408<\/li>\n<li><span style=\"color: #ff0000;\">RouteValueDictionary<\/span><\/li>\n<li>NET Core MVC \u7684<span style=\"color: #ff0000;\">ModelState<\/span><\/li>\n<\/ul>\n<p><strong>\u73b0\u5728\u5c31\u8bd5\u8bd5<\/strong><\/p>\n<p>.NET 8 \u8c03\u8bd5\u589e\u5f3a\u529f\u80fd\u73b0\u5728\u5df2\u7ecf\u5728 .NET 8 RC1 \u4e2d\u63d0\u4f9b\u3002\u60a8\u53ef\u4ee5\u6309\u7167\u4e0b\u9762\u7684\u6b65\u9aa4\u5c1d\u8bd5\u4e00\u4e0b\uff0c\u7136\u540e\u8ba9\u6211\u4eec\u77e5\u9053\u60a8\u7684\u60f3\u6cd5\uff1a<\/p>\n<ol>\n<li>\u4e0b\u8f7d\u6700\u65b0\u7684 .NET 8 \u7248\u672c\u3002<\/li>\n<li>\u542f\u52a8 Visual Studio 2022\uff08\u6216\u60a8\u9996\u9009\u7684 IDE\uff09\u5e76\u521b\u5efaNET Core \u6216 Worker Service \u5e94\u7528\u7a0b\u5e8f\u3002<\/li>\n<li>\u8bbe\u7f6e\u65ad\u70b9\u5e76\u6309 F5 \u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u5e76\u8fdb\u884c\u8c03\u8bd5\u3002<\/li>\n<\/ol>\n<p>\u611f\u8c22\u60a8\u5c1d\u8bd5 .NET 8 \u548c .NET 8 \u8c03\u8bd5\u589e\u5f3a\u529f\u80fd\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u7bc7\u7ffb\u8bd1\u4e8eJames Newton-King\u7684Debugging Enhancements in .NET 8 &nbsp; \u5f00\u53d1\u4eba\u5458\u559c\u6b22 .NET \u5f3a\u5927\u4e14\u7528\u6237\u53cb\u597d\u7684\u8c03\u8bd5\u4f53\u9a8c\u3002\u60a8\u53ef\u4ee5\u5728\u60a8\u9009\u62e9\u7684 IDE \u4e2d\u8bbe\u7f6e\u65ad\u70b9\uff0c\u542f\u52a8\u5df2\u7ecf\u9644\u52a0\u4e0a\u8c03\u8bd5\u5668\u7684\u7a0b\u5e8f\uff0c\u9010\u6b65\u6267\u884c\u4ee3\u7801\u5e76\u67e5\u770b .NET \u5e94\u7528\u7a0b\u5e8f\u7684\u72b6\u6001\u3002 \u5728 .NET 8 \u4e2d\uff0c\u6211\u4eec\u81f4\u529b\u4e8e\u6539\u5584 .NET \u5e94\u7528\u4e2d\u5e38\u7528\u7c7b\u578b\u7684\u8c03\u8bd5\u4f53\u9a8c\u3002\u8fd9\u4e9b\u5305\u62ec\uff1a HttpContext\u4e0e\u5176\u4f19\u4f34 WebApplication MVC and Razor Pages gRPC \u7aef\u70b9\u5143\u6570\u636e \u65e5\u5fd7 \u914d\u7f6e \u60a8\u4e0d\u9700\u8981\u6df1\u5165\u4e86\u89e3\u8fd9\u4e9b\u7c7b\u578b\u7684\u5185\u90e8\u7ed3\u6784\u5c31\u53ef\u4ee5\u627e\u5230\u6709\u5173\u5e94\u7528\u7a0b\u5e8f\u7684\u4fe1\u606f\u3002\u6211\u4eec\u4e3a\u5e38\u7528\u7684 .NET \u7c7b\u578b\u6dfb\u52a0\u4e86\u81ea\u5b9a\u4e49\u8c03\u8bd5\u5c5e\u6027\u7684\u529f\u80fd\u6765\u663e\u793a\u8c03\u8bd5\u6458\u8981\u4ee5\u53ca\u63d0\u4f9b\u7b80\u5316\u7684\u8c03\u8bd5\u4ee3\u7406\u3002 HttpContext\u4e0e\u5176\u4f19\u4f34 HttpContext\u3001HttpRequest \u548c HttpResponse \u5bf9\u4e8e\u4f7f\u7528ASP.NET Core\u6784\u5efaWeb\u5e94\u7528\u7a0b\u5e8f\u7684\u5f00\u53d1\u4eba\u5458\u6765\u8bf4\u5e94\u8be5\u662f\u975e\u5e38\u719f\u6089\u7684\u3002\u5982\u679c\u60a8\u60f3\u67e5\u770b HTTP \u8bf7\u6c42\u7684\u72b6\u6001\uff0c\u5c31\u80af\u5b9a\u9700\u8981\u8c03\u8bd5\u8fd9\u4e9b\u7c7b\u578b\u3002 \u6211\u4eec\u5ba1\u67e5\u4e86 ASP.NET Core \u7684 HTTP \u7c7b\u578b\u7684\u5c5e\u6027\uff0c\u4ee5\u4fbf\u5b83\u4eec\u66f4\u5bb9\u6613\u4e0e\u8c03\u8bd5\u5668\u4e00\u8d77\u4f7f\u7528\u3002\u67e5\u770b\u8bf7\u6c42\u548c\u54cd\u5e94\u503c\uff08\u4f8b\u5982header\u3001cookie\u3001\u67e5\u8be2\u5b57\u7b26\u4e32\u548c\u8868\u5355\u503c\uff09\u53d8\u5f97\u66f4\u52a0\u5bb9\u6613\uff0c\u73b0\u5728HttpRequest\u548cHttpResponse\u8fd8\u663e\u793a\u4e86\u7528\u6237\u53cb\u597d\u7684\u7c7b\u578b\u6458\u8981\uff0c\u50cfHTTP\u8bf7\u6c42URL\u6216HTTP\u54cd\u5e94\u72b6\u6001\u7801\u4e4b\u7c7b\u7684\u5173\u952e\u4fe1\u606f\u5373\u523b\u53ef\u89c1\u3002 \u4e0b\u9762\u7684\u5c4f\u5e55\u622a\u56fe\u663e\u793a\u4e86\u5bf9HttpContext\u76f8\u5173\u7c7b\u578b\u7684\u6539\u8fdb\uff1a .NET 7 .NET 8 \u76f8\u6bd4\u4e4b\u524d\u597d\u4e86\u5f88\u591a\uff01\u5c3d\u7ba1\u9690\u85cf\u4e86\u4e00\u4e9b\u6570\u636e\uff0c\u4f46\u6ca1\u6709\u4e22\u5931\u4efb\u4f55\u5185\u5bb9\u3002 \u60a8\u53ef\u4ee5\u9009\u62e9Raw View\u4ee5\u67e5\u770b\u6240\u6709\u5b57\u6bb5\u548c\u5c5e\u6027\u3002 [&hellip;]<\/p>\n","protected":false},"author":97248,"featured_media":500,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[16],"class_list":["post-496","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet-ch","tag-net-8"],"acf":[],"blog_post_summary":"<p>\u672c\u7bc7\u7ffb\u8bd1\u4e8eJames Newton-King\u7684Debugging Enhancements in .NET 8 &nbsp; \u5f00\u53d1\u4eba\u5458\u559c\u6b22 .NET \u5f3a\u5927\u4e14\u7528\u6237\u53cb\u597d\u7684\u8c03\u8bd5\u4f53\u9a8c\u3002\u60a8\u53ef\u4ee5\u5728\u60a8\u9009\u62e9\u7684 IDE \u4e2d\u8bbe\u7f6e\u65ad\u70b9\uff0c\u542f\u52a8\u5df2\u7ecf\u9644\u52a0\u4e0a\u8c03\u8bd5\u5668\u7684\u7a0b\u5e8f\uff0c\u9010\u6b65\u6267\u884c\u4ee3\u7801\u5e76\u67e5\u770b .NET \u5e94\u7528\u7a0b\u5e8f\u7684\u72b6\u6001\u3002 \u5728 .NET 8 \u4e2d\uff0c\u6211\u4eec\u81f4\u529b\u4e8e\u6539\u5584 .NET \u5e94\u7528\u4e2d\u5e38\u7528\u7c7b\u578b\u7684\u8c03\u8bd5\u4f53\u9a8c\u3002\u8fd9\u4e9b\u5305\u62ec\uff1a HttpContext\u4e0e\u5176\u4f19\u4f34 WebApplication MVC and Razor Pages gRPC \u7aef\u70b9\u5143\u6570\u636e \u65e5\u5fd7 \u914d\u7f6e \u60a8\u4e0d\u9700\u8981\u6df1\u5165\u4e86\u89e3\u8fd9\u4e9b\u7c7b\u578b\u7684\u5185\u90e8\u7ed3\u6784\u5c31\u53ef\u4ee5\u627e\u5230\u6709\u5173\u5e94\u7528\u7a0b\u5e8f\u7684\u4fe1\u606f\u3002\u6211\u4eec\u4e3a\u5e38\u7528\u7684 .NET \u7c7b\u578b\u6dfb\u52a0\u4e86\u81ea\u5b9a\u4e49\u8c03\u8bd5\u5c5e\u6027\u7684\u529f\u80fd\u6765\u663e\u793a\u8c03\u8bd5\u6458\u8981\u4ee5\u53ca\u63d0\u4f9b\u7b80\u5316\u7684\u8c03\u8bd5\u4ee3\u7406\u3002 HttpContext\u4e0e\u5176\u4f19\u4f34 HttpContext\u3001HttpRequest \u548c HttpResponse \u5bf9\u4e8e\u4f7f\u7528ASP.NET Core\u6784\u5efaWeb\u5e94\u7528\u7a0b\u5e8f\u7684\u5f00\u53d1\u4eba\u5458\u6765\u8bf4\u5e94\u8be5\u662f\u975e\u5e38\u719f\u6089\u7684\u3002\u5982\u679c\u60a8\u60f3\u67e5\u770b HTTP \u8bf7\u6c42\u7684\u72b6\u6001\uff0c\u5c31\u80af\u5b9a\u9700\u8981\u8c03\u8bd5\u8fd9\u4e9b\u7c7b\u578b\u3002 \u6211\u4eec\u5ba1\u67e5\u4e86 ASP.NET Core \u7684 HTTP \u7c7b\u578b\u7684\u5c5e\u6027\uff0c\u4ee5\u4fbf\u5b83\u4eec\u66f4\u5bb9\u6613\u4e0e\u8c03\u8bd5\u5668\u4e00\u8d77\u4f7f\u7528\u3002\u67e5\u770b\u8bf7\u6c42\u548c\u54cd\u5e94\u503c\uff08\u4f8b\u5982header\u3001cookie\u3001\u67e5\u8be2\u5b57\u7b26\u4e32\u548c\u8868\u5355\u503c\uff09\u53d8\u5f97\u66f4\u52a0\u5bb9\u6613\uff0c\u73b0\u5728HttpRequest\u548cHttpResponse\u8fd8\u663e\u793a\u4e86\u7528\u6237\u53cb\u597d\u7684\u7c7b\u578b\u6458\u8981\uff0c\u50cfHTTP\u8bf7\u6c42URL\u6216HTTP\u54cd\u5e94\u72b6\u6001\u7801\u4e4b\u7c7b\u7684\u5173\u952e\u4fe1\u606f\u5373\u523b\u53ef\u89c1\u3002 \u4e0b\u9762\u7684\u5c4f\u5e55\u622a\u56fe\u663e\u793a\u4e86\u5bf9HttpContext\u76f8\u5173\u7c7b\u578b\u7684\u6539\u8fdb\uff1a .NET 7 .NET 8 \u76f8\u6bd4\u4e4b\u524d\u597d\u4e86\u5f88\u591a\uff01\u5c3d\u7ba1\u9690\u85cf\u4e86\u4e00\u4e9b\u6570\u636e\uff0c\u4f46\u6ca1\u6709\u4e22\u5931\u4efb\u4f55\u5185\u5bb9\u3002 \u60a8\u53ef\u4ee5\u9009\u62e9Raw View\u4ee5\u67e5\u770b\u6240\u6709\u5b57\u6bb5\u548c\u5c5e\u6027\u3002 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/posts\/496","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/users\/97248"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/comments?post=496"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/posts\/496\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/media\/500"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/media?parent=496"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/categories?post=496"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/tags?post=496"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}