[Translation] ASP.NET Core updated in the .NET Core 3.1 Preview 1

.NET Core 3.1 Preview 1 is now available. This release focuses primarily on bug fixes, but it also contains some new features.
It is this version of ASP.NET Core new features:

  • Partial class support for Razor components of
  • Passing parameters to a top-level component
  • In HttpSysServer in support shared queue
  • Significant changes in the SameSite cookies

In addition to .NET Core 3.1 Preview release, we also released an update Blazor WebAssembly now requires .NET Core 3.1. To use Blazor WebAssembly, you need to install .NET Core 3.1 Preview 1 and the latest preview version of Visual Studio.

For additional details and known issues, see the release notes

let's start

To .NET Core 3.1 Preview 1 is used ASP.NET Core, you need to install the .NET Core 1 Preview SDK .

If you are using on Windows Visual Studio, for the best experience, we recommend that you install the latest preview version of Visual Studio 2019 16.4. Install Visual Studio 2019 16.4 will also install the .NET Core 3.1 Preview 1, so you need to install it separately. Blazor developed using the .NET Core 3.1, Visual Studio 2019 16.4 is a must.

To install the latest Blazor WebAssembly template, run the following command:

dotnet new -i Microsoft.AspNetCore.Blazor.Templates::3.1.0-preview1.19508.20

Upgrading existing projects

To convert an existing ASP.NET Core 3.0 project to upgrade to 3.1 Preview 1:

  • All items for netcoreapp3.0 updates netcoreapp3.1
  • All Microsoft.AspNetCore. * Package references updated to 3.1.0-preview1.19506.1

See ASP.NET Core 3.1 in significant changes to the complete list.

Now you should have been ready to use .NET Core 3.1 Preview 1!

Partial class support for Razor components of

Razor components now generates distribution classes. You can use the Razor components defined as a written code partial class code-behind file, without defining all the components of the code in a single file.

For example, instead of using @codethe block to define the default Counter component, but rather this:
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++;
   }
}

Now, you can use some class separates the code into the code-behind file:
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++;
       }
   }
}

Passing parameters to a top-level component

Now, Blazor Server application can pass parameters to the top-level component (top-level components) during the initial rendering. Previously, you can use RenderMode.Staticto pass parameters to the top-level component. In the published version, supports RenderMode.Serverand RenderModel.ServerPrerendered. Any given parameter values are serialized as JSON, and included in the initial response.

For example, you can use to render a particular current count Counter components as follows

@(await Html.RenderComponentAsync<Counter>(RenderMode.ServerPrerendered, new { CurrentCount = 123 }))

In HttpSysServer in support shared queue

In addition to the existing behavior HttpSysServer create an anonymous request queue, we also create or add to an existing named HTTP.sys request queue function.
This program should enable it: has a queue HTTP.Sys controller process is independent of the listener process, which can retain the existing connection and request queued in between across multiple listeners process is restarted.

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            // ...
            webBuilder.UseHttpSys(options =>
            {
                options.RequestQueueName = "MyExistingQueue",
                options.RequestQueueMode = RequestQueueMode.CreateOrAttach
            })
        });

Significant changes in the SameSite cookies

This updated version of the ASP.NET Core in SameSite cookie behavior in order to meet the latest standard browser enforced. For more information about these changes and their impact on existing applications, see https://github.com/aspnet/Announcements/issues/390.

Give feedback

We hope you like the new features in this version of ASP.NET Core preview! By GitHub submit problems, please let us know what you think.

Thank you for trying ASP.NET Core!

Guess you like

Origin www.cnblogs.com/sesametech-netcore/p/11723840.html