.NET 5 Preview 6 is now available and is ready for evaluation. Here’s what’s new in this release:
HttpRequest
and HttpResponse
To get started with ASP.NET Core in .NET 5.0 Preview 6 install the .NET 5.0 SDK.
You need to use Visual Studio 2019 16.7 or Visual Studio 2019 for Mac 8.6 to use .NET 5.0. Install the latest version of the C# extension, to use .NET 5.0 with Visual Studio Code.
To upgrade an existing ASP.NET Core 5.0 Preview 5 app to ASP.NET Core 5.0 Preview 6:
5.0.0-preview.6.*
.5.0.0-preview.6.*
.See the full list of breaking changes in ASP.NET Core 5.0.
That’s it! You should now be all set to use .NET 5 Preview 6.
The Blazor WebAssembly template is now included in the .NET 5 SDK along with the Blazor Server template. To create a Blazor WebAssembly project, simply run dotnet new blazorwasm
.
HttpRequest
and HttpResponse
You can now easily read and write JSON data from an HttpRequest
and HttpResponse
using the new ReadFromJsonAsync
and WriteAsJsonAsync
extension methods. These extension methods use the System.Text.Json
serializer to handle the JSON data. You can also check if a request has a JSON content type using the new HasJsonContentType
extension method.
The JSON extension methods can be combined with endpoint routing to create JSON APIs in a style of programming we call “route to code”. It is a new option for developers who want to create basic JSON APIs in a lightweight way. For example, a web app that has only a handful of endpoints might choose to use route to code rather than the full functionality of ASP.NET Core MVC.
endpoints.MapGet("/weather/{city:alpha}", async context =>
{
var city = (string)context.Request.RouteValues["city"];
var weather = GetFromDatabase(city);
await context.Response.WriteAsJsonAsync(weather);
});
Find out more about the JSON extension methods in a recent On .NET interview about route to code.
You can now allow anonymous access to an endpoint using the simpler AllowAnonymous
extension method when using endpoint routing.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/", async context =>
{
await context.Response.WriteAsync("Hello World!");
})
.AllowAnonymous();
});
}
#aspnetcore #blazor