Fix “Unable to Find Required Services” for AddAuthorization in ASP.NET Core
Quick answer. Register authorization services before Build. Define policies where needed, and configure authentication separately for endpoints that require identity.
Applies to. ASP.NET Core with the built-in dependency injection container and modern Program.cs hosting.
What does the failure look like?
A minimal host calls UseAuthorization without registering authorization services via AddAuthorization or another registration that provides them.
How do you diagnose the cause?
Confirm the exception is thrown by the UseAuthorization registration guard. Check conditional host setup, service registrations and the application branch. Authorization evaluates policies. Authentication establishes an identity using its configured scheme.
Worked example
Add the authorization services in the host. Existing authentication services and the scheme used by the endpoint must also be configured. Verify both a permitted and denied request instead of testing only startup.
builder.Services.AddAuthorization(options =>
options.AddPolicy("CanReadOrders", policy =>
policy.RequireAuthenticatedUser()));If the preview blocks the Copy button, select the snippet and copy it directly.
How do you verify the fix?
| Check | Expected behavior |
|---|---|
| Repeat the failing operation in development or staging | The host starts and policy evaluation distinguishes permitted and denied requests. |
| Repeat normal traffic and a relevant negative case | Valid work completes and the failure path remains observable |
These are expected outcomes. The example was not executed against a deployed application.
Frequently asked question
Does authorization register an authentication scheme?
Configure the authentication scheme separately when a policy needs an identity.
Comments
Post a Comment