Skip to content

Commit 7699bab

Browse files
committed
Address feedback
- put connection string in its own variable - add explicit call to UseRouting() to avoid issue with middleware that re-runs the pipeline with a different path (e.g. UseExceptionHandler)
1 parent dde6daa commit 7699bab

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,12 @@
4646

4747
// Add services to the container.
4848
#if (IndividualLocalAuth)
49+
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
4950
builder.Services.AddDbContext<ApplicationDbContext>(options =>
5051
#if (UseLocalDB)
51-
options.UseSqlServer(
52-
builder.Configuration.GetConnectionString("DefaultConnection")));
52+
options.UseSqlServer(connectionString));
5353
#else
54-
options.UseSqlite(
55-
builder.Configuration.GetConnectionString("DefaultConnection")));
54+
options.UseSqlite(connectionString));
5655
#endif
5756
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
5857
builder.Services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
@@ -140,6 +139,8 @@
140139

141140
app.UseStaticFiles();
142141

142+
app.UseRouting();
143+
143144
#if (OrganizationalAuth || IndividualAuth)
144145
app.UseAuthentication();
145146
app.UseAuthorization();

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@
2929

3030
// Add services to the container.
3131
#if (IndividualLocalAuth)
32+
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
3233
builder.Services.AddDbContext<ApplicationDbContext>(options =>
3334
#if (UseLocalDB)
34-
options.UseSqlServer(
35-
builder.Configuration.GetConnectionString("DefaultConnection")));
35+
options.UseSqlServer(connectionString));
3636
#else
37-
options.UseSqlite(
38-
builder.Configuration.GetConnectionString("DefaultConnection")));
37+
options.UseSqlite(connectionString));
3938
#endif
4039
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
4140

@@ -106,6 +105,8 @@
106105
app.UseBlazorFrameworkFiles();
107106
app.UseStaticFiles();
108107

108+
app.UseRouting();
109+
109110
#if (IndividualLocalAuth)
110111
app.UseIdentityServer();
111112
#endif

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,12 @@
3838

3939
// Add services to the container.
4040
#if (IndividualLocalAuth)
41+
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
4142
builder.Services.AddDbContext<ApplicationDbContext>(options =>
4243
#if (UseLocalDB)
43-
options.UseSqlServer(
44-
builder.Configuration.GetConnectionString("DefaultConnection")));
44+
options.UseSqlServer(connectionString));
4545
#else
46-
options.UseSqlite(
47-
builder.Configuration.GetConnectionString("DefaultConnection")));
46+
options.UseSqlite(connectionString));
4847
#endif
4948
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
5049

@@ -124,6 +123,8 @@
124123
#endif
125124
app.UseStaticFiles();
126125

126+
app.UseRouting();
127+
127128
#if (OrganizationalAuth || IndividualAuth)
128129
app.UseAuthentication();
129130
#endif

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,12 @@
3838

3939
// Add services to the container.
4040
#if (IndividualLocalAuth)
41+
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
4142
builder.Services.AddDbContext<ApplicationDbContext>(options =>
4243
#if (UseLocalDB)
43-
options.UseSqlServer(
44-
builder.Configuration.GetConnectionString("DefaultConnection")));
44+
options.UseSqlServer(connectionString));
4545
#else
46-
options.UseSqlite(
47-
builder.Configuration.GetConnectionString("DefaultConnection")));
46+
options.UseSqlite(connectionString));
4847
#endif
4948
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
5049

@@ -125,6 +124,8 @@
125124
#endif
126125
app.UseStaticFiles();
127126

127+
app.UseRouting();
128+
128129
#if (OrganizationalAuth || IndividualAuth)
129130
app.UseAuthentication();
130131
#endif

0 commit comments

Comments
 (0)