Skip to content

Commit d1c349f

Browse files
authored
Automatically UseDeveloperExceptionPage in WebApplication (#34616)
- UseDeveloperExceptionPage in WebApplication - Update project templates
1 parent 5712409 commit d1c349f

File tree

9 files changed

+31
-30
lines changed

9 files changed

+31
-30
lines changed

src/DefaultBuilder/src/WebApplicationBuilder.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ private void ConfigureApplication(WebHostBuilderContext context, IApplicationBui
114114
{
115115
Debug.Assert(_builtApplication is not null);
116116

117+
if (context.HostingEnvironment.IsDevelopment())
118+
{
119+
app.UseDeveloperExceptionPage();
120+
}
121+
117122
var implicitRouting = false;
118123

119124
// The endpoints were already added on the outside

src/ProjectTemplates/Web.ProjectTemplates/content/BlazorServerWeb-CSharp/Program.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,15 @@
107107
var app = builder.Build();
108108

109109
// Configure the HTTP request pipeline.
110+
#if (IndividualLocalAuth)
110111
if (app.Environment.IsDevelopment())
111112
{
112-
app.UseDeveloperExceptionPage();
113-
#if (IndividualLocalAuth)
114113
app.UseMigrationsEndPoint();
115-
#endif
116114
}
117115
else
116+
#else
117+
if (!app.Environment.IsDevelopment())
118+
#endif
118119
{
119120
app.UseExceptionHandler("/Error");
120121
#if (RequiresHttps)

src/ProjectTemplates/Web.ProjectTemplates/content/ComponentsWebAssembly-CSharp/Server/Program.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if (OrganizationalAuth || IndividualB2CAuth || IndividualLocalAuth)
1+
#if (OrganizationalAuth || IndividualB2CAuth || IndividualLocalAuth)
22
using Microsoft.AspNetCore.Authentication;
33
#endif
44
#if (OrganizationalAuth || IndividualB2CAuth)
@@ -74,15 +74,16 @@
7474
var app = builder.Build();
7575

7676
// Configure the HTTP request pipeline.
77+
#if (IndividualLocalAuth)
7778
if (app.Environment.IsDevelopment())
7879
{
79-
app.UseDeveloperExceptionPage();
80-
#if (IndividualLocalAuth)
8180
app.UseMigrationsEndPoint();
82-
#endif
8381
app.UseWebAssemblyDebugging();
8482
}
8583
else
84+
#else
85+
if (!app.Environment.IsDevelopment())
86+
#endif
8687
{
8788
app.UseExceptionHandler("/Error");
8889
#if (RequiresHttps)
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
var builder = WebApplication.CreateBuilder(args);
22
var app = builder.Build();
33

4-
if (app.Environment.IsDevelopment())
5-
{
6-
app.UseDeveloperExceptionPage();
7-
}
8-
94
app.MapGet("/", () => "Hello World!");
105

116
app.Run();

src/ProjectTemplates/Web.ProjectTemplates/content/EmptyWeb-FSharp/Program.fs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ let main args =
77
let builder = WebApplication.CreateBuilder(args)
88
let app = builder.Build()
99

10-
if app.Environment.IsDevelopment() then
11-
app.UseDeveloperExceptionPage() |> ignore
12-
1310
app.MapGet("/", Func<string>(fun () -> "Hello World!")) |> ignore
1411

1512
app.Run()

src/ProjectTemplates/Web.ProjectTemplates/content/GrpcService-CSharp/Program.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111
var app = builder.Build();
1212

1313
// Configure the HTTP request pipeline.
14-
if (app.Environment.IsDevelopment())
15-
{
16-
app.UseDeveloperExceptionPage();
17-
}
18-
1914
app.MapGrpcService<GreeterService>();
2015
app.MapGet("/", () => "Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");
2116

src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Program.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
#if (IndividualLocalAuth)
2626
using Company.WebApplication1.Data;
2727
#endif
28+
#if (OrganizationalAuth || IndividualB2CAuth || IndividualLocalAuth || MultiOrgAuth || GenerateGraph)
2829

30+
#endif
2931
var builder = WebApplication.CreateBuilder(args);
3032

3133
// Add services to the container.
@@ -94,14 +96,15 @@
9496
var app = builder.Build();
9597

9698
// Configure the HTTP request pipeline.
99+
#if (IndividualLocalAuth)
97100
if (app.Environment.IsDevelopment())
98101
{
99-
app.UseDeveloperExceptionPage();
100-
#if (IndividualLocalAuth)
101102
app.UseMigrationsEndPoint();
102-
#endif
103103
}
104104
else
105+
#else
106+
if (!app.Environment.IsDevelopment())
107+
#endif
105108
{
106109
app.UseExceptionHandler("/Error");
107110
#if (RequiresHttps)

src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Program.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
#if (IndividualLocalAuth)
2626
using Company.WebApplication1.Data;
2727
#endif
28+
#if (OrganizationalAuth || IndividualB2CAuth || IndividualLocalAuth || MultiOrgAuth || GenerateGraph)
2829

30+
#endif
2931
var builder = WebApplication.CreateBuilder(args);
3032

3133
// Add services to the container.
@@ -95,14 +97,15 @@
9597
var app = builder.Build();
9698

9799
// Configure the HTTP request pipeline.
100+
#if (IndividualLocalAuth)
98101
if (app.Environment.IsDevelopment())
99102
{
100-
app.UseDeveloperExceptionPage();
101-
#if (IndividualLocalAuth)
102103
app.UseMigrationsEndPoint();
103-
#endif
104104
}
105105
else
106+
#else
107+
if (!app.Environment.IsDevelopment())
108+
#endif
106109
{
107110
app.UseExceptionHandler("/Home/Error");
108111
#if (RequiresHttps)

src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp/Program.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
#if (EnableOpenAPI)
1212
using Microsoft.OpenApi.Models;
1313
#endif
14+
#if (OrganizationalAuth || IndividualB2CAuth || GenerateGraph || EnableOpenAPI)
1415

16+
#endif
1517
var builder = WebApplication.CreateBuilder(args);
1618

1719
// Add services to the container.
@@ -53,14 +55,13 @@
5355
var app = builder.Build();
5456

5557
// Configure the HTTP request pipeline.
56-
if (builder.Environment.IsDevelopment())
58+
#if (EnableOpenAPI)
59+
if (app.Environment.IsDevelopment())
5760
{
58-
app.UseDeveloperExceptionPage();
59-
#if (EnableOpenAPI)
6061
app.UseSwagger();
6162
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Company.WebApplication1 v1"));
62-
#endif
6363
}
64+
#endif
6465
#if (RequiresHttps)
6566

6667
app.UseHttpsRedirection();

0 commit comments

Comments
 (0)