Update authorization samples to use AddAuthorizationBuilder() for .NET 7+ #36718
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Multiple authorization documentation articles use
AddAuthorization()which triggers ASP0025 analyzer warning in .NET 7+. The modern pattern isAddAuthorizationBuilder().Changes
Following pattern from PR #36675:
Samples Updated:
limitingidentitybyscheme- "Over18" policy, multiple authentication schemesresourcebased- "EditPolicy" with custom requirementsroles- "RequireAdministratorRole", "ElevatedRights" policiesStructure:
7.x/folders with updated samples (target net7.0)6.x/folders (preserved as-is)>= aspnetcore-7.0and= aspnetcore-6.0Example
Before (.NET 6):
After (.NET 7+):
Original prompt
This section details on the original issue you should resolve
<issue_title>More code samples for authorization use legacy approach for registering in DI container</issue_title>
<issue_description>### Description
A continuation of #36666. Also see its related PR #36675
More code samples under authorization have the same issue: they use
AddAuthorization()instead ofAddAuthorizationBuilder().Namely:
Page URL
https://learn.microsoft.com/en-us/aspnet/core/security/authorization/limitingidentitybyscheme?view=aspnetcore-10.0#selecting-the-scheme-with-policies
Content source URL
https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/security/authorization/limitingidentitybyscheme.md
Document ID
0096c365-2f4e-5d21-89a0-c4f10fcb0ed9
Platform Id
099e63e1-c27f-9f00-8885-c551419ae35a
Article author
@wadepickett
Metadata
Related Issues</issue_description>
<agent_instructions>Read the issue description plus all documents linked in the description plus read the comments which include additonal instructions.</agent_instructions>
Comments on the Issue (you are @copilot in this section)
@wadepickett Thanks again @abatishchev! @wadepickett ## 🤖 AI Triage SummaryThis preliminary assessment report was run by: @wadepickett
Date: 2026-01-30
Issue: 36717
Model: GitHub Copilot
Issue Analysis: More code samples for authorization use legacy approach for registering in DI container
✅ Issue Validation
Status: Valid and actionable
📋 Issue Summary
This issue is a continuation of #36666, which was addressed by PR dotnet/AspNetCore.Docs#36675. Multiple code samples throughout the authorization documentation section use
AddAuthorization()instead ofAddAuthorizationBuilder(). This pattern triggers analyzer warning ASP0025. Since .NET 7+, the recommended approach is to useAddAuthorizationBuilder()which is more concise and follows current best practices.The approach established in PR #36675 should be followed: create new 7.x code samples while preserving existing 6.x samples for backward compatibility.
📁 Potentially Affected Files
1. Limiting Identity by Scheme - Program.cs
aspnetcore/security/authorization/limitingidentitybyscheme/samples/AuthScheme/Program.cssnippet2region - "Over18" policyaspnetcore/security/authorization/limitingidentitybyscheme/samples/AuthScheme/Program.cssnippet_maregion - Default authorization policyaspnetcore/security/authorization/limitingidentitybyscheme.md2. Resource-based Authorization - Program.cs
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
Internal previews