diff --git a/src/Http/Routing/src/EndpointMiddleware.cs b/src/Http/Routing/src/EndpointMiddleware.cs index 08e5bb1db7b3..41919ff00cc0 100644 --- a/src/Http/Routing/src/EndpointMiddleware.cs +++ b/src/Http/Routing/src/EndpointMiddleware.cs @@ -1,8 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System; -using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Cors.Infrastructure; using Microsoft.AspNetCore.Http; @@ -90,7 +88,7 @@ private static void ThrowMissingAuthMiddlewareException(Endpoint endpoint) throw new InvalidOperationException($"Endpoint {endpoint.DisplayName} contains authorization metadata, " + "but a middleware was not found that supports authorization." + Environment.NewLine + - "Configure your application startup by adding app.UseAuthorization() inside the call to Configure(..) in the application startup code. The call to app.UseAuthorization() must appear between app.UseRouting() and app.UseEndpoints(...)."); + "Configure your application startup by adding app.UseAuthorization() in the application startup code. If there are calls to app.UseRouting() and app.UseEndpoints(...), the call to app.UseAuthorization() must go between them."); } private static void ThrowMissingCorsMiddlewareException(Endpoint endpoint) @@ -98,7 +96,7 @@ private static void ThrowMissingCorsMiddlewareException(Endpoint endpoint) throw new InvalidOperationException($"Endpoint {endpoint.DisplayName} contains CORS metadata, " + "but a middleware was not found that supports CORS." + Environment.NewLine + - "Configure your application startup by adding app.UseCors() inside the call to Configure(..) in the application startup code. The call to app.UseCors() must appear between app.UseRouting() and app.UseEndpoints(...)."); + "Configure your application startup by adding app.UseCors() in the application startup code. If there are calls to app.UseRouting() and app.UseEndpoints(...), the call to app.UseCors() must go between them."); } private static partial class Log diff --git a/src/Http/Routing/test/FunctionalTests/EndpointRoutingIntegrationTest.cs b/src/Http/Routing/test/FunctionalTests/EndpointRoutingIntegrationTest.cs index 9a1f82673467..0d6f2f4fa77c 100644 --- a/src/Http/Routing/test/FunctionalTests/EndpointRoutingIntegrationTest.cs +++ b/src/Http/Routing/test/FunctionalTests/EndpointRoutingIntegrationTest.cs @@ -20,13 +20,13 @@ public class EndpointRoutingIntegrationTest private static readonly RequestDelegate TestDelegate = async context => await Task.Yield(); private static readonly string AuthErrorMessage = "Endpoint / contains authorization metadata, but a middleware was not found that supports authorization." + Environment.NewLine + - "Configure your application startup by adding app.UseAuthorization() inside the call to Configure(..) in the application startup code. " + - "The call to app.UseAuthorization() must appear between app.UseRouting() and app.UseEndpoints(...)."; + "Configure your application startup by adding app.UseAuthorization() in the application startup code. " + + "If there are calls to app.UseRouting() and app.UseEndpoints(...), the call to app.UseAuthorization() must go between them."; private static readonly string CORSErrorMessage = "Endpoint / contains CORS metadata, but a middleware was not found that supports CORS." + Environment.NewLine + - "Configure your application startup by adding app.UseCors() inside the call to Configure(..) in the application startup code. " + - "The call to app.UseCors() must appear between app.UseRouting() and app.UseEndpoints(...)."; + "Configure your application startup by adding app.UseCors() in the application startup code. " + + "If there are calls to app.UseRouting() and app.UseEndpoints(...), the call to app.UseCors() must go between them."; [Fact] public async Task AuthorizationMiddleware_WhenNoAuthMetadataIsConfigured() diff --git a/src/Http/Routing/test/UnitTests/EndpointMiddlewareTest.cs b/src/Http/Routing/test/UnitTests/EndpointMiddlewareTest.cs index 5bdef13fe567..2f6482ec716f 100644 --- a/src/Http/Routing/test/UnitTests/EndpointMiddlewareTest.cs +++ b/src/Http/Routing/test/UnitTests/EndpointMiddlewareTest.cs @@ -1,16 +1,12 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System; -using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Cors.Infrastructure; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Http.Features; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; using Moq; -using Xunit; namespace Microsoft.AspNetCore.Routing { @@ -101,8 +97,8 @@ public async Task Invoke_WithEndpoint_ThrowsIfAuthAttributesWereFound_ButAuthMid // Arrange var expected = "Endpoint Test contains authorization metadata, but a middleware was not found that supports authorization." + Environment.NewLine + - "Configure your application startup by adding app.UseAuthorization() inside the call to Configure(..) in the application startup code. " + - "The call to app.UseAuthorization() must appear between app.UseRouting() and app.UseEndpoints(...)."; + "Configure your application startup by adding app.UseAuthorization() in the application startup code. " + + "If there are calls to app.UseRouting() and app.UseEndpoints(...), the call to app.UseAuthorization() must go between them."; var httpContext = new DefaultHttpContext { RequestServices = new ServiceProvider() @@ -198,8 +194,8 @@ public async Task Invoke_WithEndpoint_ThrowsIfCorsMetadataWasFound_ButCorsMiddle // Arrange var expected = "Endpoint Test contains CORS metadata, but a middleware was not found that supports CORS." + Environment.NewLine + - "Configure your application startup by adding app.UseCors() inside the call to Configure(..) in the application startup code. " + - "The call to app.UseCors() must appear between app.UseRouting() and app.UseEndpoints(...)."; + "Configure your application startup by adding app.UseCors() in the application startup code. " + + "If there are calls to app.UseRouting() and app.UseEndpoints(...), the call to app.UseCors() must go between them."; var httpContext = new DefaultHttpContext { RequestServices = new ServiceProvider() diff --git a/src/Security/Authorization/Policy/src/AuthorizationAppBuilderExtensions.cs b/src/Security/Authorization/Policy/src/AuthorizationAppBuilderExtensions.cs index 2fccd211f1db..1fa8f2dd0a6b 100644 --- a/src/Security/Authorization/Policy/src/AuthorizationAppBuilderExtensions.cs +++ b/src/Security/Authorization/Policy/src/AuthorizationAppBuilderExtensions.cs @@ -1,7 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization.Policy; using Microsoft.Extensions.DependencyInjection; @@ -42,8 +41,7 @@ private static void VerifyServicesRegistered(IApplicationBuilder app) { throw new InvalidOperationException(Resources.FormatException_UnableToFindServices( nameof(IServiceCollection), - nameof(PolicyServiceCollectionExtensions.AddAuthorization), - "ConfigureServices(...)")); + nameof(PolicyServiceCollectionExtensions.AddAuthorization))); } } } diff --git a/src/Security/Authorization/Policy/src/Resources.resx b/src/Security/Authorization/Policy/src/Resources.resx index 15d6f7d53c0f..93cc19ce4f71 100644 --- a/src/Security/Authorization/Policy/src/Resources.resx +++ b/src/Security/Authorization/Policy/src/Resources.resx @@ -118,6 +118,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - Unable to find the required services. Please add all the required services by calling '{0}.{1}' inside the call to '{2}' in the application startup code. + Unable to find the required services. Please add all the required services by calling '{0}.{1}' in the application startup code. \ No newline at end of file diff --git a/src/Security/Authorization/test/AuthorizationAppBuilderExtensionsTests.cs b/src/Security/Authorization/test/AuthorizationAppBuilderExtensionsTests.cs index 73cc1138721a..1f19e2486012 100644 --- a/src/Security/Authorization/test/AuthorizationAppBuilderExtensionsTests.cs +++ b/src/Security/Authorization/test/AuthorizationAppBuilderExtensionsTests.cs @@ -61,8 +61,7 @@ public void UseAuthorization_MissingRequiredSevices_FriendlyErrorMessage() // Assert Assert.Equal( "Unable to find the required services. Please add all the required services by calling " + - "'IServiceCollection.AddAuthorization' inside the call to 'ConfigureServices(...)' " + - "in the application startup code.", + "'IServiceCollection.AddAuthorization' in the application startup code.", ex.Message); }