[Translation] ASP.NET CORE update in .NET Core 3.1 Preview 1

.NET Core 3.1 Preview 1 is now available. This version mainly focuses on bug fixes, but also contains some new features.
This is a new feature of this version of ASP.NET Core:

  • Part of the class support for Razor components
  • Pass parameters to top-level components
  • Support for shared queues in HttpSysServer
  • Major changes in SameSite cookies

In addition to the release of .NET Core 3.1 Preview, we also released Blazor The update of 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 other details and known issues, please see the release notes

Get started

To use ASP.NET Core in .NET Core 3.1 Preview 1 , You need to install the .NET Core Preview 1 SDK.

If you are using Visual Studio on Windows, for the best experience, it is recommended that you install the latest preview version of Visual Studio 2019 16.4. Installing Visual Studio 2019 16.4 will also install .NET Core 3.1 Preview 1, so you don’t need to install it separately. In order to use Blazor development in .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

Upgrade the existing project

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

  • Update all projects targeting netcoreapp3.0 to netcoreapp3.1
  • Update all Microsoft.AspNetCore.* package references to 3.1.0-preview1.19506.1
  • < /ul>

    See also the completed list of major changes in ASP.NET Core 3.1.

    Now, you should all be ready to use .NET Core 3.1 Preview 1!

    Part of class support for Razor components

    Razor components are now generated as distributed classes. You can use code-behind files defined as partial classes to write the code of Razor components instead of defining all the code of the component in a single file.

    For example, instead of using the @code block to define the default Counter component, it’s like this:
    Counter.razor

    @page "/counter"

    Counter



    Current count: @currentCount





    @code {
    int currentCount = 0;

    void IncrementCount()
    {
    currentCount++;
    }
    }

    Now, you can use some classes to separate the code into code-behind files:< br> Counter.razor

    @page "/counter"

    Counter



    Current count: @currentCount



    Counter.razor.cs

    namespace BlazorApp1.Pages
    {
    public partial class Counter
    {
    int currentCount = 0;

    void IncrementCount()
    {
    currentCount++;
    }
    }
    }

    Pass parameters to top-level components

    Now, Blazor Server applications can Pass parameters to the top level during initial rendering Components (top-level components). Previously, you could only use RenderMode.Static to pass parameters to the top-level component. In the version released this time, both RenderMode.Server and RenderModel.ServerPrerendered are supported. Any specified parameter values ​​will be serialized into JSON and included in the initial response.

    For example, you can render the Counter component with a specific current count as shown below

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

    Support for shared queues in HttpSysServer

    In addition to the existing behavior of HttpSysServer to create anonymous request queues, we also added creating or appending to existing named HTTP.sys requests The function of the queue.
    This should enable the following scenario: The HTTP.Sys controller process that owns the queue is independent of the listener process, so that existing connections and queued requests can be preserved between restarts across multiple listener processes.

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

    Major changes in SameSite cookies

    This version updates the behavior of SameSite cookies in ASP.NET Core to comply with the latest standards enforced by browsers. For details on 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 preview of ASP.NET Core! Please let us know what you think by submitting an issue on GitHub.

    Thank you for trying ASP.NET Core!

    share picture

Leave a Comment

Your email address will not be published.