What's new in ASP.NET Core 10.0
This article highlights the most significant changes in ASP.NET Core 10.0 with links to relevant documentation.
This article will be updated as new preview releases are made available. See the Asp.Net Core announcement page until this page is updated.
Blazor
This section describes new features for Blazor.
QuickGrid RowClass
parameter
Apply a stylesheet class to a row of the grid based on the row item using the new RowClass
parameter. In the following example, the ApplyRowStyle
method is called on each row to conditionally apply a stylesheet class based on the row item:
<QuickGrid ... RowClass="ApplyRowStyle">
...
</QuickGrid>
@code {
private string ApplyRowStyle({TYPE} rowItem) =>
rowItem.{PROPERTY} == {VALUE} ? "{CSS STYLE CLASS}" : null;
}
For more information, see ASP.NET Core Blazor `QuickGrid` component.
Blazor script
In prior releases of .NET, the Blazor script is served from an embedded resource in the ASP.NET Core shared framework. In .NET 10 or later, the Blazor script is served as a static web asset with automatic compression and fingerprinting.
For more information, see the following resources:
Route template highlights
The [Route]
attribute now supports route syntax highlighting to help visualize the structure of the route template:
SignalR
This section describes new features for SignalR.
Minimal APIs
This section describes new features for minimal APIs.
OpenAPI
This section describes new features for OpenAPI.
OpenAPI 3.1 support
ASP.NET Core has added support for generating OpenAPI version 3.1 documents in .NET 10. Despite the minor version bump, OpenAPI 3.1 is a significant update to the OpenAPI specification, in particular with full support for JSON Schema draft 2020-12.
Some of the changes you will see in the generated OpenAPI document include:
- Nullable types no longer have the
nullable: true
property in the schema. - Instead of a
nullable: true
property, they have atype
keyword whose value is an array that includesnull
as one of the types.
With this feature, the default OpenAPI version for generated documents is3.1
. The version can be changed by explicitly setting the OpenApiVersion property of the OpenApiOptions in the configureOptions
delegate parameter of AddOpenApi.
builder.Services.AddOpenApi(options =>
{
// Specify the OpenAPI version to use.
options.OpenApiVersion = Microsoft.OpenApi.OpenApiSpecVersion.OpenApi3_0;
});
When generating the OpenAPI document at build time, the OpenAPI version can be selected by setting the --openapi-version
in the OpenApiGenerateDocumentsOptions
MSBuild item.
<!-- Configure build-time OpenAPI generation to produce an OpenAPI 3.0 document. -->
<OpenApiGenerateDocumentsOptions>--openapi-version OpenApi3_0</OpenApiGenerateDocumentsOptions>
OpenAPI 3.1 support was primarly added in the following PR.
OpenAPI 3.1 breaking changes
Support for OpenAPI 3.1 requires an update to the underlying OpenAPI.NET library to a new major version, 2.0. This new version has some breaking changes from the previous version. The breaking changes may impact apps if they have any document, operation, or schema transformers.
One of the most significant changes is that the OpenApiAny
class has been dropped in favor of using JsonNode
directly. Transformers that use OpenApiAny
need to be updated to use JsonNode
. The following diff shows the changes in schema transformer from .NET 9 to .NET 10:
options.AddSchemaTransformer((schema, context, cancellationToken) =>
{
if (context.JsonTypeInfo.Type == typeof(WeatherForecast))
{
- schema.Example = new OpenApiObject
+ schema.Example = new JsonObject
{
- ["date"] = new OpenApiString(DateTime.Now.AddDays(1).ToString("yyyy-MM-dd")),
+ ["date"] = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd"),
- ["temperatureC"] = new OpenApiInteger(0),
+ ["temperatureC"] = 0,
- ["temperatureF"] = new OpenApiInteger(32),
+ ["temperatureF"] = 32,
- ["summary"] = new OpenApiString("Bracing"),
+ []"summary"] = "Bracing",
};
}
return Task.CompletedTask;
});
Note that these changes are necessary even when only congfiguring the OpenAPI version to 3.0.
OpenAPI in Yaml
ASP.NET now supports serving the generated OpenAPI document in YAML format. YAML can be more concise than JSON, eliminating curly braces and quotation marks when these can be inferred. YAML also supports multi-line strings, which can be useful for long descriptions.
To configure an app to serve the generated OpenAPI document in YAML format, specify the endpoint in the MapOpenApi call with a ".yaml" or ".yml" suffix, as shown in the following example:
app.MapOpenApi("/openapi/{documentName}.yaml");
Support for:
- YAML is currently only available for the the OpenAPI served from the OpenAPI endpoint.
- Generating OpenAPI documents in YAML format at build time is added in a future preview.
See this PR which added support for serving the generated OpenAPI document in YAML format.
Response description on ProducesResponseType
The ProducesAttribute, ProducesResponseTypeAttribute, and ProducesDefaultResponseType attributes now accept an optional string parameter, Description
, that will set the description of the response. Here's an example:
[HttpGet(Name = "GetWeatherForecast")]
[ProducesResponseType<IEnumerable<WeatherForecast>>(StatusCodes.Status200OK, Description = "The weather forecast for the next 5 days.")]
public IEnumerable<WeatherForecast> Get()
{
And the generated OpenAPI:
"responses": {
"200": {
"description": "The weather forecast for the next 5 days.",
"content": {
Community contribution by Sander ten Brinke 🙏
Authentication and authorization
This section describes new features for authentication and authorization.
Miscellaneous
This section describes miscellaneous new features in ASP.NET Core 10.0.
Better support for testing apps with top-level statements
.NET 10 now has better support for testing apps that use top-level statements. Previously developers had to manually add public partial class Program
to the Program.cs
file so that the test project could reference the Program class
. public partial class Program
was required because the top-level statement feature in C# 9 generated a Program class
that was declared as internal.
In .NET 10, a source generator is used to generate the public partial class Program
declaration if the programmer didn't declare it explicitly. Additionally, an analyzer was added to detect when public partial class Program
is declared explicitly and advise the developer to remove it.
The following PRs contribited to this feature:
Detect if URL is local using RedirectHttpResult.IsLocalUrl
Use the new RedirectHttpResult.IsLocalUrl(url)
helper method to detect if a URL is local. A URL is considered local if the following are true:
- It doesn't have the host or authority section.
- It has an absolute path.
URLs using virtual paths "~/"
are also local.
IsLocalUrl
is useful for validating URLs before redirecting to them to prevent open redirection attacks.
if (RedirectHttpResult.IsLocalUrl(url))
{
return Results.LocalRedirect(url);
}
Thank you @martincostello for this contribution!
Related content
ASP.NET Core