.NET Core 3.1 Preview 1如今可用。此版本主要侧重于错误修复,但同时也包含一些新功能。
这是此版本的ASP.NET Core的新增功能:git
除了.NET Core 3.1 Preview版本发布以外,咱们还发布了Blazor WebAssembly的更新,如今要求.NET Core 3.1. 若要使用Blazor WebAssembly,您须要安装.NET Core 3.1 Preview 1以及Visual Studio的最新预览版。github
有关其余详细信息和已知问题,请参见发行说明web
要在.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 开发,Visual Studio 2019 16.4是必须的。cookie
要安装最新的Blazor WebAssembly模板,请运行如下命令:app
dotnet new -i Microsoft.AspNetCore.Blazor.Templates::3.1.0-preview1.19508.20
ui
要将现有的ASP.NET Core 3.0项目升级到3.1 Preview 1:spa
另请参阅ASP.NET Core 3.1中重大更改的完成列表。code
如今,您应该都已准备好使用.NET Core 3.1 Preview 1!component
Razor components如今做为分布类生成。你可使用定义为局部类的代码隐藏文件编写Razor components的代码,而不用在单个文件中定义该组件的全部代码。
例如,不是用@code
块定义默认的Counter component,而是这样:
Counter.razor
@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++; } }
如今,你可使用部分类将代码分离为代码隐藏文件:
Counter.razor
@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++; } } }
如今,Blazor Server应用程序能够在初始渲染期间将参数传递给顶级组件(top-level components)。之前,你只能使用RenderMode.Static
将参数传递给顶级组件。在这次发布的版本中,同时支持RenderMode.Server
和RenderModel.ServerPrerendered
。任何指定的参数值都将序列化为JSON,并包含在初始响应中。
例如,你可使用特定的当前计数来渲染Counter组件,以下所示
@(await Html.RenderComponentAsync<Counter>(RenderMode.ServerPrerendered, new { CurrentCount = 123 }))
除了HttpSysServer建立匿名请求队列的现有行为外,咱们还添加了建立或附加到现有命名HTTP.sys 请求队列的功能。
这应该启用一下方案:拥有队列的HTTP.Sys控制器进程独立于侦听器进程,从而能够在跨多个侦听器进程从新启动之间保留现有的链接和排队的请求。
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { // ... webBuilder.UseHttpSys(options => { options.RequestQueueName = "MyExistingQueue", options.RequestQueueMode = RequestQueueMode.CreateOrAttach }) });
此版本更新了ASP.NET Core中SameSite cookie的行为,以符合浏览器强制执行的最新标准。有关这些更改及其对现有应用程序的影响的详细信息,请参见https://github.com/aspnet/Announcements/issues/390。
咱们但愿您喜欢此ASP.NET Core预览版中的新功能!经过在GitHub上提交问题,请让咱们知道您的想法。
感谢您试用ASP.NET Core!