ASP.NET Core在 .NET Core 3.1 Preview 1中的更新
.NET Core 3.1 Preview 1現(xiàn)在可用。此版本主要側(cè)重于錯誤修復,但同時也包含一些新功能。
- 對Razor components的部分類支持 
- 將參數(shù)傳遞給頂級組件 
- 在HttpSysServer中支持共享隊列 
- 在SameSite cookies的重大更改 
除了.NET Core 3.1 Preview版本發(fā)布之外,我們還發(fā)布了Blazor WebAssembly的更新,現(xiàn)在要求.NET Core 3.1. 若要使用Blazor WebAssembly,您需要安裝.NET Core 3.1 Preview 1以及Visual Studio的最新預覽版。
有關(guān)其他詳細信息和已知問題,請參見發(fā)行說明
開始吧
要在.NET Core 3.1 Preview 1 中使用ASP.NET Core,需要安裝.NET Core Preview 1 SDK。
如果你是在Windows上使用的Visual Studio,為獲得最佳體驗,建議你安裝Visual Studio 2019 16.4 的最新預覽版。安裝Visual Studio 2019 16.4 還將安裝上.NET Core 3.1 Preview 1,因此你無需單獨安裝它。為在.NET Core 3.1 中使用Blazor 開發(fā),Visual Studio 2019 16.4是必須的。
要安裝最新的Blazor WebAssembly模板,請運行以下命令:
dotnet new -i Microsoft.AspNetCore.Blazor.Templates::3.1.0-preview1.19508.20
升級現(xiàn)有項目
要將現(xiàn)有的ASP.NET Core 3.0項目升級到3.1 Preview 1:
- 將所有針對netcoreapp3.0的項目更新為netcoreapp3.1 
- 將所有Microsoft.AspNetCore.*軟件包引用更新為3.1.0-preview1.19506.1 
另請參閱ASP.NET Core 3.1中重大更改的完成列表。
現(xiàn)在,您應(yīng)該都已準備好使用.NET Core 3.1 Preview 1!
對Razor components的部分類支持
Razor components現(xiàn)在作為分布類生成。你可以使用定義為局部類的代碼隱藏文件編寫Razor components的代碼,而不用在單個文件中定義該組件的所有代碼。
例如,不是用@code塊定義默認的Counter component,而是這樣:
@page "/counter"<h1>Counter</h1><p>Current count: @currentCount</p><button class="btn btn-primary" @onclick="IncrementCount">Click me</button>@code {int currentCount = 0;void IncrementCount(){currentCount++;} }現(xiàn)在,你可以使用部分類將代碼分離為代碼隱藏文件:
@page "/counter"<h1>Counter</h1><p>Current count: @currentCount</p><button class="btn btn-primary" @onclick="IncrementCount">Click me</button>Counter.razor.cs
namespace BlazorApp1.Pages {public partial class Counter{int currentCount = 0;void IncrementCount(){currentCount++;}} }將參數(shù)傳遞給頂級組件
現(xiàn)在,Blazor Server應(yīng)用程序可以在初始渲染期間將參數(shù)傳遞給頂級組件(top-level components)。以前,你只能使用RenderMode.Static將參數(shù)傳遞給頂級組件。在此次發(fā)布的版本中,同時支持RenderMode.Server和RenderModel.ServerPrerendered。任何指定的參數(shù)值都將序列化為JSON,并包含在初始響應(yīng)中。
例如,你可以使用特定的當前計數(shù)來渲染Counter組件,如下所示
@(await Html.RenderComponentAsync<Counter>(RenderMode.ServerPrerendered, new { CurrentCount = 123 }))在HttpSysServer中支持共享隊列
除了HttpSysServer創(chuàng)建匿名請求隊列的現(xiàn)有行為外,我們還添加了創(chuàng)建或附加到現(xiàn)有命名HTTP.sys 請求隊列的功能。
public static IHostBuilder CreateHostBuilder(string[] args) =>Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(webBuilder =>{// ...webBuilder.UseHttpSys(options =>{options.RequestQueueName = "MyExistingQueue",options.RequestQueueMode = RequestQueueMode.CreateOrAttach})});在SameSite cookies的重大更改
此版本更新了ASP.NET Core中SameSite cookie的行為,以符合瀏覽器強制執(zhí)行的最新標準。有關(guān)這些更改及其對現(xiàn)有應(yīng)用程序的影響的詳細信息,請參見https://github.com/aspnet/Announcements/issues/390。
給予反饋
我們希望您喜歡此ASP.NET Core預覽版中的新功能!通過在GitHub上提交問題,請讓我們知道您的想法。
感謝您試用ASP.NET Core!
總結(jié)
以上是生活随笔為你收集整理的ASP.NET Core在 .NET Core 3.1 Preview 1中的更新的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: .NET实时2D渲染入门·动态时钟
- 下一篇: .NET Core 3.0 新 JSON
