Remove the DeveloperExceptionPage middleware from WebHost.CreateDefaultBuilder:
- The templates still have it explicitly and it's best to have middleware added by the app directly
This commit is contained in:
parent
eb09fc7dd4
commit
4d5e1076c9
|
|
@ -188,7 +188,6 @@ namespace Microsoft.AspNetCore
|
||||||
})
|
})
|
||||||
.ConfigureServices(services =>
|
.ConfigureServices(services =>
|
||||||
{
|
{
|
||||||
services.AddSingleton<IStartupFilter, WebHostStartupFilter>();
|
|
||||||
services.AddTransient<IConfigureOptions<KestrelServerOptions>, KestrelServerOptionsSetup>();
|
services.AddTransient<IConfigureOptions<KestrelServerOptions>, KestrelServerOptionsSetup>();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore
|
|
||||||
{
|
|
||||||
internal class WebHostStartupFilter : IStartupFilter
|
|
||||||
{
|
|
||||||
public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
|
|
||||||
{
|
|
||||||
return app =>
|
|
||||||
{
|
|
||||||
var env = app.ApplicationServices.GetService<IHostingEnvironment>();
|
|
||||||
if (env.IsDevelopment())
|
|
||||||
{
|
|
||||||
app.UseDeveloperExceptionPage();
|
|
||||||
}
|
|
||||||
next(app);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -54,10 +54,8 @@ namespace Microsoft.AspNetCore.Tests
|
||||||
await ExecuteTestApp(applicationName, async (deploymentResult, logger) =>
|
await ExecuteTestApp(applicationName, async (deploymentResult, logger) =>
|
||||||
{
|
{
|
||||||
var response = await RetryHelper.RetryRequest(() => deploymentResult.HttpClient.GetAsync(string.Empty), logger, deploymentResult.HostShutdownToken);
|
var response = await RetryHelper.RetryRequest(() => deploymentResult.HttpClient.GetAsync(string.Empty), logger, deploymentResult.HostShutdownToken);
|
||||||
var errorResponse = await RetryHelper.RetryRequest(() => deploymentResult.HttpClient.GetAsync("/error"), logger, deploymentResult.HostShutdownToken);
|
|
||||||
|
|
||||||
var responseText = await response.Content.ReadAsStringAsync();
|
var responseText = await response.Content.ReadAsStringAsync();
|
||||||
var errorResponseText = await errorResponse.Content.ReadAsStringAsync();
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Assert server is Kestrel
|
// Assert server is Kestrel
|
||||||
|
|
@ -65,9 +63,6 @@ namespace Microsoft.AspNetCore.Tests
|
||||||
|
|
||||||
// The application name will be sent in response when all asserts succeed in the test app.
|
// The application name will be sent in response when all asserts succeed in the test app.
|
||||||
Assert.Equal(applicationName, responseText);
|
Assert.Equal(applicationName, responseText);
|
||||||
|
|
||||||
// Assert UseDeveloperExceptionPage is called in WebHostStartupFilter.
|
|
||||||
Assert.Contains("An unhandled exception occurred while processing the request.", errorResponseText);
|
|
||||||
}
|
}
|
||||||
catch (XunitException)
|
catch (XunitException)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -30,10 +30,6 @@ namespace CreateDefaultBuilderApp
|
||||||
})
|
})
|
||||||
.Configure(app =>
|
.Configure(app =>
|
||||||
{
|
{
|
||||||
app.Map("/error", subApp =>
|
|
||||||
{
|
|
||||||
subApp.Run(context => throw new Exception());
|
|
||||||
});
|
|
||||||
app.Run(context =>
|
app.Run(context =>
|
||||||
{
|
{
|
||||||
return context.Response.WriteAsync(responseMessage);
|
return context.Response.WriteAsync(responseMessage);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue