Skip to content

Upgrade WebDemo sample to .NET 8 #1059

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.32015.303
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebDemoNet6", "WebDemoNet6\WebDemoNet6.csproj", "{6003C39B-DE37-4799-B8C6-B5BDB58A6461}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6003C39B-DE37-4799-B8C6-B5BDB58A6461}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6003C39B-DE37-4799-B8C6-B5BDB58A6461}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6003C39B-DE37-4799-B8C6-B5BDB58A6461}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6003C39B-DE37-4799-B8C6-B5BDB58A6461}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {04296B4E-C016-487C-818B-AC3CCF5993E7}
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36119.2 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebDemo", "WebDemo\WebDemo.csproj", "{7D342A3D-3386-F48E-2FD0-340DF151EAD4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7D342A3D-3386-F48E-2FD0-340DF151EAD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7D342A3D-3386-F48E-2FD0-340DF151EAD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7D342A3D-3386-F48E-2FD0-340DF151EAD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7D342A3D-3386-F48E-2FD0-340DF151EAD4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6D318ED3-1FC2-4ADD-AE37-C4BF4D7D7CAC}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.FeatureManagement.Mvc;

namespace WebDemoNet6.Pages
namespace WebDemo.Pages
{
[FeatureGate("Beta")]
public class BetaModel : PageModel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Diagnostics;

namespace WebDemoNet6.Pages
namespace WebDemo.Pages
{
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Options;

namespace WebDemoNet6.Pages
namespace WebDemo.Pages
{
public class IndexModel : PageModel
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Microsoft.AspNetCore.Mvc;
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace WebDemoNet6.Pages
namespace WebDemo.Pages
{
public class PrivacyModel : PageModel
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<title>@ViewData["Title"] - Azure App Configuration Demo</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/WebDemoNet6.styles.css" asp-append-version="true" />
<link rel="stylesheet" href="~/WebDemo.styles.css" asp-append-version="true" />
<style>
@RenderSection("InlineStyles", required: false)
</style>
Expand Down Expand Up @@ -46,7 +46,7 @@

<footer class="border-top footer text-muted">
<div class="container">
&copy; WebDemo for .Net 6 - <a asp-area="" asp-page="/Privacy">Privacy</a>
&copy; WebDemo for Azure App Configuration
</div>
</footer>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@using WebDemoNet6
@namespace WebDemoNet6.Pages
@using WebDemo
@namespace WebDemo.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Microsoft.FeatureManagement.AspNetCore
65 changes: 65 additions & 0 deletions examples/DotNetCore/WebDemo/WebDemo/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
using Azure.Identity;
using Microsoft.FeatureManagement;
using WebDemo;

var builder = WebApplication.CreateBuilder(args);

// Get the Azure App Configuration endpoint from environment or settings
string? appConfigEndpoint = builder.Configuration["AppConfig:Endpoint"] ??
Environment.GetEnvironmentVariable("AppConfigEndpoint");
Copy link
Preview

Copilot AI May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider using the ASP.NET Core environment variable naming convention (AppConfig__Endpoint) so the configuration binder can automatically map nested settings.

Suggested change
Environment.GetEnvironmentVariable("AppConfigEndpoint");
Environment.GetEnvironmentVariable("AppConfig__Endpoint");

Copilot uses AI. Check for mistakes.


// Load configuration from Azure App Configuration
if (!string.IsNullOrEmpty(appConfigEndpoint))
{
builder.Configuration.AddAzureAppConfiguration(options =>
{
// Use DefaultAzureCredential for Microsoft Entra ID authentication
options.Connect(new Uri(appConfigEndpoint), new DefaultAzureCredential())
// Load all keys that start with `WebDemo:` and have no label
.Select("WebDemo:*")
// Reload configuration if any selected key-values have changed
.ConfigureRefresh(refreshOptions =>
{
refreshOptions.RegisterAll();
})
// Load all feature flags with no label
.UseFeatureFlags();
});
}

// Add services to the container
builder.Services.AddRazorPages();
builder.Services.AddHttpContextAccessor();

// Add Azure App Configuration and feature management services to the container
builder.Services.AddAzureAppConfiguration();
builder.Services.AddFeatureManagement();

// Bind configuration to the Settings object
builder.Services.Configure<Settings>(builder.Configuration.GetSection("WebDemo:Settings"));

var app = builder.Build();

// Configure the HTTP request pipeline
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts
app.UseHsts();
}

// Use Azure App Configuration middleware for dynamic configuration refresh
app.UseAzureAppConfiguration();

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();
app.UseAuthorization();

app.MapRazorPages();

app.Run();
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace WebDemoNet6
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
namespace WebDemo
{
public class Settings
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="5.0.0" />
<PackageReference Include="Microsoft.FeatureManagement.AspNetCore" Version="2.5.0" />
<PackageReference Include="Azure.Identity" Version="1.14.0" />
<PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="8.2.0" />
<PackageReference Include="Microsoft.FeatureManagement.AspNetCore" Version="4.0.0" />
</ItemGroup>

</Project>
55 changes: 0 additions & 55 deletions examples/DotNetCore/WebDemoNet6/WebDemoNet6/Program.cs

This file was deleted.

12 changes: 6 additions & 6 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ This example showcases a .NET isolated worker model Function App, which operates

This example showcases a .NET class library Function App, which runs in-process with the Azure Functions runtime. It demonstrates how to enable dynamic configuration and utilize feature flags from App Configuration. Additionally, it illustrates how to leverage App Configuration for a queue-triggered function, with the trigger settings stored in App Configuration.

### [ConsoleApplication](./DotNetCore/ConsoleApplication)
### [Console App](./DotNetCore/ConsoleApplication)

This example demonstrates how to enable dynamic configuration from App Configuration in a console app written in .NET Core.
This example demonstrates how to enable dynamic configuration from App Configuration in a .NET console app using the minimal project template style.

### [WebDemo (.NET 6)](./DotNetCore/WebDemoNet6)
### [Web App](./DotNetCore/WebDemo)

This example is an ASP.NET Core app, which uses the modernized project template introduced in .NET 6. It demonstrates how to enable dynamic configuration and use feature flags from App Configuration.
This example is an ASP.NET Core web app, which uses the minimal project template style. It demonstrates how to enable dynamic configuration and use feature flags from App Configuration.

### [WebDemoWithEventHub](./DotNetCore/WebDemoWithEventHub/WebDemoWithEventHub)

Expand All @@ -30,11 +30,11 @@ This ASP.NET Core app demonstrates how to enable dynamic configuration from App

This example demonstrates how to enable dynamic configuration from App Configuration in a Web Job app written in .NET Core.

### [WebDemo (.NET Framework)](./DotNetFramework/WebDemo)
### [MVC Web App (.NET Framework)](./DotNetFramework/WebDemo)

This ASP.NET web application is a .NET Framework MVC 5 app. It leverages the [configuration builder](https://www.nuget.org/packages/Microsoft.Configuration.ConfigurationBuilders.AzureAppConfiguration/) for App Configuration to load configuration to App Settings and consumes from the `ConfigurationManager`. As is the design of the .NET Framework App Settings, the configuration will only be updated upon app restart.

### [WebFormApp (.NET Framework)](./DotNetFramework/WebFormApp)
### [WebForm App (.NET Framework)](./DotNetFramework/WebFormApp)

This ASP.NET web application is a .NET Framework Web Forms app. It demonstrates how to leverage the App Configuration [.NET Standard provider library](https://www.nuget.org/packages/Microsoft.Extensions.Configuration.AzureAppConfiguration/) to achieve dynamic configuration and control feature launches with feature flags. The same technique applies to .NET Framework MVC apps.

Expand Down