Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions aspnetcore/blazor/forms/binding.md
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,15 @@ To use the preceding component in the [starship example form (`Starship3.razor`/
+ <EngineeringApprovalInputDerived @bind-Value="Model!.IsValidatedDesign" />
```

If the component that inherits from <xref:Microsoft.AspNetCore.Components.Forms.InputBase%601> is ever statically rendered, assign the <xref:Microsoft.AspNetCore.Components.Forms.InputBase%601.NameAttributeValue?displayProperty=nameWithType> property to the `name` attribute of `<input>` elements:

```razor
<input @bind="CurrentValue" @bind:after="AfterChange" class="@CssClass"
type="checkbox" name="@NameAttributeValue" />
```

The preceding assignment isn't necessary if the component is guaranteed to always render interactively.

### Input component with full developer control

The following example component:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,47 @@ This article explains how to load JavaScript (JS) in a Blazor Web App with stati

Some apps depend on JS to perform initialization tasks that are specific to each page. When using Blazor's enhanced navigation feature, which allows the user to avoid reloading the entire page, page-specific JS may not be executed again as expected each time an enhanced page navigation occurs.

To avoid this problem, we don't recommended relying on page-specific `<script>` elements placed outside of the layout file applied to the component. Instead, scripts should register an [`afterWebStarted` JS initializer](xref:blazor/fundamentals/startup#javascript-initializers) to perform initialization logic and use an event listener (`blazor.addEventListener("enhancedload", callback)`) to listen for page updates caused by enhanced navigation.
:::moniker range=">= aspnetcore-9.0"

To avoid this problem, we don't recommended relying on page-specific `<script>` elements placed outside of the layout file applied to the component. Instead, scripts should register an [`afterWebStarted` JS initializer](xref:blazor/fundamentals/startup#javascript-initializers) to perform initialization logic and use an event listener to listen for page updates caused by enhanced navigation.

## Events

In the following event listener examples, the `{CALLBACK}` placeholder is the callback function.

* Enhanced navigation start (`enhancednavigationstart`) triggers a callback before an enhanced navigation occurs:

```javascript
blazor.addEventListener("enhancednavigationstart", {CALLBACK});
```

* Enhanced navigation end (`enhancednavigationend`) triggers a callback after an enhanced navigation occurs:

```javascript
blazor.addEventListener("enhancednavigationend", {CALLBACK});
```

* Enhanced navigation page load (`enhancedload`) triggers a callback each time the page updates due to an enhanced navigation, including [streaming updates](xref:blazor/components/rendering#streaming-rendering):

```javascript
blazor.addEventListener("enhancedload", {CALLBACK});
```

:::moniker-end

:::moniker range="< aspnetcore-9.0"

To avoid this problem, we don't recommended relying on page-specific `<script>` elements placed outside of the layout file applied to the component. Instead, scripts should register an [`afterWebStarted` JS initializer](xref:blazor/fundamentals/startup#javascript-initializers) to perform initialization logic and use an event listener to listen for page updates caused by enhanced navigation:

```javascript
blazor.addEventListener("enhancedload", {CALLBACK});
```

In the preceding example, the `{CALLBACK}` placeholder is the callback function.

:::moniker-end

## Enhanced page load script example

The following example demonstrates one way to configure JS code to run when a statically-rendered page with enhanced navigation is initially loaded or updated.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

Expand All @@ -11,14 +11,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SQLite" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0">
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="9.0.0" />
</ItemGroup>

</Project>
63 changes: 63 additions & 0 deletions aspnetcore/data/ef-rp/intro/samples/cu90/Data/DbInitializer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#define FIRST
#if FIRST // First DbInitializer used
// <snippet>
using ContosoUniversity.Models;

namespace ContosoUniversity.Data
{
public static class DbInitializer
{
public static void Initialize(SchoolContext context)
{
// Look for any students.
if (context.Students.Any())
{
return; // DB has been seeded
}

context.Students.AddRange(
[
new() { FirstMidName = "Carson", LastName = "Alexander", EnrollmentDate = DateTime.Parse("2019-09-01") },
new() { FirstMidName = "Meredith", LastName = "Alonso", EnrollmentDate = DateTime.Parse("2017-09-01") },
new() { FirstMidName = "Arturo", LastName = "Anand", EnrollmentDate = DateTime.Parse("2018-09-01") },
new() { FirstMidName = "Gytis", LastName = "Barzdukas", EnrollmentDate = DateTime.Parse("2017-09-01") },
new() { FirstMidName = "Yan", LastName = "Li", EnrollmentDate = DateTime.Parse("2017-09-01") },
new() { FirstMidName = "Peggy", LastName = "Justice", EnrollmentDate = DateTime.Parse("2016-09-01") },
new() { FirstMidName = "Laura", LastName = "Norman", EnrollmentDate = DateTime.Parse("2018-09-01") },
new() { FirstMidName = "Nino", LastName = "Olivetto", EnrollmentDate = DateTime.Parse("2019-09-01") },
]);
context.SaveChanges();

context.Courses.AddRange(
[
new() { CourseID = 1050, Title = "Chemistry", Credits = 3 },
new() { CourseID = 4022, Title = "Microeconomics", Credits = 3 },
new() { CourseID = 4041, Title = "Macroeconomics", Credits = 3 },
new() { CourseID = 1045, Title = "Calculus", Credits = 4 },
new() { CourseID = 3141, Title = "Trigonometry", Credits = 4 },
new() { CourseID = 2021, Title = "Composition", Credits = 3 },
new() { CourseID = 2042, Title = "Literature", Credits = 4 },
]);
context.SaveChanges();

context.Enrollments.AddRange(
[
new() { StudentID = 1, CourseID = 1050, Grade = Grade.A },
new() { StudentID = 1, CourseID = 4022, Grade = Grade.C },
new() { StudentID = 1, CourseID = 4041, Grade = Grade.B },
new() { StudentID = 2, CourseID = 1045, Grade = Grade.B },
new() { StudentID = 2, CourseID = 3141, Grade = Grade.F },
new() { StudentID = 2, CourseID = 2021, Grade = Grade.F },
new() { StudentID = 3, CourseID = 1050 },
new() { StudentID = 4, CourseID = 1050 },
new() { StudentID = 4, CourseID = 4022, Grade = Grade.F},
new() { StudentID = 5, CourseID = 4041, Grade = Grade.C},
new() { StudentID = 6, CourseID = 1045 },
new() { StudentID = 7, CourseID = 3141, Grade = Grade.A},
]);
context.SaveChanges();
}
}
}
// </snippet>
#endif
69 changes: 0 additions & 69 deletions aspnetcore/data/ef-rp/intro/samples/cu90/Data/DbInitializer1.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace ContosoUniversity.Data
{
public class SchoolContext : DbContext
{
public SchoolContext (DbContextOptions<SchoolContext> options)
public SchoolContext(DbContextOptions<SchoolContext> options)
: base(options)
{
}
Expand Down
9 changes: 3 additions & 6 deletions aspnetcore/data/ef-rp/intro/samples/cu90/Models/Department.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public class Department
public decimal Budget { get; set; }

[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}",
ApplyFormatInEditMode = true)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
[Display(Name = "Start Date")]
public DateTime StartDate { get; set; }

Expand Down Expand Up @@ -52,8 +51,7 @@ public class Department
public decimal Budget { get; set; }

[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}",
ApplyFormatInEditMode = true)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
[Display(Name = "Start Date")]
public DateTime StartDate { get; set; }

Expand Down Expand Up @@ -87,8 +85,7 @@ public class Department
public decimal Budget { get; set; }

[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}",
ApplyFormatInEditMode = true)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
[Display(Name = "Start Date")]
public DateTime StartDate { get; set; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -56,7 +56,7 @@ public async Task<IActionResult> OnPostAsync()
}
catch (DbUpdateConcurrencyException)
{
if (!StudentExists(Student.ID))
if (!await StudentExistsAsync(Student.ID))
{
return NotFound();
}
Expand All @@ -69,9 +69,9 @@ public async Task<IActionResult> OnPostAsync()
return RedirectToPage("./Index");
}

private bool StudentExists(int id)
private Task<bool> StudentExistsAsync(int id)
{
return _context.Students.Any(e => e.ID == id);
return _context.Students.AnyAsync(e => e.ID == id);
}
}
}
8 changes: 4 additions & 4 deletions aspnetcore/fundamentals/aot/native-aot-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ASP.NET Core 8.0 introduces support for [.NET native ahead-of-time (AOT)](/dotne
> [!NOTE]
> * The Native AOT feature is currently in preview.
> * In .NET 8, not all ASP.NET Core features are compatible with Native AOT.
> * Tabs are provided for the [.NET CLI](/dotnet/core/tools/) and [Visual Studio](https://visualstudio.microsoft.com/vs/preview/) instructions:
> * Tabs are provided for the [.NET CLI](/dotnet/core/tools/) and [Visual Studio](https://visualstudio.microsoft.com/downloads/) instructions:
> * Visual Studio is a prerequisite even if the CLI tab is selected.
> * The CLI must be used to publish even if the Visual Studio tab is selected.

Expand All @@ -34,18 +34,18 @@ ASP.NET Core 8.0 introduces support for [.NET native ahead-of-time (AOT)](/dotne

* [!INCLUDE[](~/includes/8.0-SDK.md)]
* On Linux, see [Prerequisites for Native AOT deployment](/dotnet/core/deploying/native-aot/?tabs=net8plus#prerequisites-for-native-aot-deployment).
* [Visual Studio 2022 Preview](https://visualstudio.microsoft.com/vs/preview/) with the **Desktop development with C++** workload installed.
* [Visual Studio 2022](https://visualstudio.microsoft.com/downloads/) with the **Desktop development with C++** workload installed.

![Visual Studio workload selection dialog showing "Desktop development with C++" selected.](~/fundamentals/aot/_static/cpponly.png)

> [!NOTE]
> Visual Studio 2022 Preview is required because Native AOT requires [link.exe](/cpp/build/reference/linker-options) and the Visual C++ static runtime libraries. There are no plans to support Native AOT ***without*** Visual Studio.
> Visual Studio 2022 is required because Native AOT requires [link.exe](/cpp/build/reference/linker-options) and the Visual C++ static runtime libraries. There are no plans to support Native AOT ***without*** Visual Studio.

# [Visual Studio](#tab/visual-studio)

* [!INCLUDE[](~/includes/8.0-SDK.md)]

* [Visual Studio 2022 Preview](https://visualstudio.microsoft.com/vs/preview/) with the following workloads installed:
* [Visual Studio 2022](https://visualstudio.microsoft.com/downloads/) with the following workloads installed:
* **ASP.NET and web development**
* **Desktop development with C++**

Expand Down
34 changes: 16 additions & 18 deletions aspnetcore/host-and-deploy/linux-nginx.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,25 +169,23 @@ To configure Nginx as a reverse proxy to forward HTTP requests to an ASP.NET Cor
---

```text
http {
map $http_connection $connection_upgrade {
"~*Upgrade" $http_connection;
default keep-alive;
}
map $http_connection $connection_upgrade {
"~*Upgrade" $http_connection;
default keep-alive;
}

server {
listen 80;
server_name example.com *.example.com;
location / {
proxy_pass http://127.0.0.1:5000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
server {
listen 80;
server_name example.com *.example.com;
location / {
proxy_pass http://127.0.0.1:5000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
```
Expand Down
9 changes: 9 additions & 0 deletions aspnetcore/release-notes/aspnetcore-9/includes/blazor.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,12 @@ The <xref:Microsoft.AspNetCore.Components.Forms.InputNumber%601> component now s
}
}
```

### New enhanced navigation events

Trigger JavaScript callbacks either before or after enhanced navigation with new event listeners:

* `blazor.addEventListener("enhancednavigationstart", {CALLBACK})`
* `blazor.addEventListener("enhancednavigationend", {CALLBACK})`

For more information, see <xref:blazor/js-interop/ssr?view=aspnetcore-9.0>.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: Learn how to set up OpenID Connect authentication in an ASP.NET Cor
monikerRange: '>= aspnetcore-8.0'
ms.author: riande
ms.custom: mvc
ms.date: 04/02/2024
ms.date: 12/2/2024
uid: security/authentication/configure-oidc-web-authentication
---
# Configure OpenID Connect Web (UI) authentication in ASP.NET Core
Expand Down Expand Up @@ -374,4 +374,4 @@ Refer to the following document:

[The OAuth 2.0 Authorization Framework](https://datatracker.ietf.org/doc/html/rfc6749)

[OAuth 2.0 Pushed Authorization Requests (PAR) RFC 9126](https://datatracker.ietf.org/doc/html/rfc9126)
[OAuth 2.0 Pushed Authorization Requests (PAR) RFC 9126](https://datatracker.ietf.org/doc/html/rfc9126)
Loading
Loading