Skip to content

Commit 4cdd594

Browse files
Update templates baseline for recent changes (#34186)
* Update templates baseline for recent changes * Add using alias to fix type name conflict in templates that were missed in the previous set of changes. * Update SPA templates - Use top-level statements - Use minimal hosting APIs - #33947 #33944 * Fix nullable issue in Blazor Server template
1 parent 5577c0d commit 4cdd594

File tree

9 files changed

+177
-287
lines changed

9 files changed

+177
-287
lines changed

src/ProjectTemplates/Web.ProjectTemplates/content/BlazorServerWeb-CSharp/Pages/CallWebApi.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ else
2121
}
2222

2323
@code {
24-
private HttpResponseMessage response;
25-
private string apiResult;
24+
private HttpResponseMessage? response;
25+
private string? apiResult;
2626

2727
protected override async Task OnInitializedAsync()
2828
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
using Microsoft.Extensions.DependencyInjection;
3333
using Microsoft.Extensions.Hosting;
3434
#if (GenerateGraph)
35-
using Microsoft.Graph;
35+
using Graph = Microsoft.Graph;
3636
#endif
3737
#if(MultiOrgAuth)
3838
using Microsoft.IdentityModel.Tokens;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
using Microsoft.Extensions.DependencyInjection;
1616
using Microsoft.Extensions.Hosting;
1717
#if (GenerateGraph)
18-
using Microsoft.Graph;
18+
using Graph = Microsoft.Graph;
1919
#endif
2020
#if (OrganizationalAuth || IndividualB2CAuth)
2121
using Microsoft.Identity.Web;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
using Microsoft.IdentityModel.Tokens;
2929
#endif
3030
#if (GenerateGraph)
31-
using Microsoft.Graph;
31+
using Graph = Microsoft.Graph;
3232
#endif
3333
#if (IndividualLocalAuth)
3434
using Company.WebApplication1.Data;
Lines changed: 85 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,92 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
2+
#if (IndividualLocalAuth)
3+
using Microsoft.AspNetCore.Authentication;
4+
#endif
5+
using Microsoft.AspNetCore.Builder;
56
using Microsoft.AspNetCore.Hosting;
7+
#if (IndividualLocalAuth)
8+
using Microsoft.AspNetCore.Identity;
9+
using Microsoft.AspNetCore.Identity.UI;
10+
#endif
11+
#if (IndividualLocalAuth)
12+
using Microsoft.EntityFrameworkCore;
13+
#endif
614
using Microsoft.Extensions.Configuration;
15+
using Microsoft.Extensions.DependencyInjection;
716
using Microsoft.Extensions.Hosting;
8-
using Microsoft.Extensions.Logging;
17+
#if (IndividualLocalAuth)
18+
using Company.WebApplication1.Data;
19+
using Company.WebApplication1.Models;
20+
#endif
921

10-
namespace Company.WebApplication1
22+
var builder = WebApplication.CreateBuilder(args);
23+
24+
// Add services to the container.
25+
#if (IndividualLocalAuth)
26+
var connectionString = Configuration.GetConnectionString("DefaultConnection");
27+
builder.Services.AddDbContext<ApplicationDbContext>(options =>
28+
#if (UseLocalDB)
29+
options.UseSqlServer(connectionString));
30+
#else
31+
options.UseSqlite(connectionString));
32+
#endif
33+
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
34+
35+
builder.Services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)
36+
.AddEntityFrameworkStores<ApplicationDbContext>();
37+
38+
builder.Services.AddIdentityServer()
39+
.AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
40+
41+
builder.Services.AddAuthentication()
42+
.AddIdentityServerJwt();
43+
#endif
44+
45+
builder.Services.AddControllersWithViews();
46+
#if (IndividualLocalAuth)
47+
builder.Services.AddRazorPages();
48+
#endif
49+
50+
var app = builder.Build();
51+
52+
// Configure the HTTP request pipeline.
53+
if (app.Environment.IsDevelopment())
54+
{
55+
app.UseDeveloperExceptionPage();
56+
#if (IndividualLocalAuth)
57+
app.UseMigrationsEndPoint();
58+
#endif
59+
}
60+
else
1161
{
12-
public class Program
13-
{
14-
public static void Main(string[] args)
15-
{
16-
CreateHostBuilder(args).Build().Run();
17-
}
18-
19-
public static IHostBuilder CreateHostBuilder(string[] args) =>
20-
Host.CreateDefaultBuilder(args)
21-
.ConfigureWebHostDefaults(webBuilder =>
22-
{
23-
webBuilder.UseStartup<Startup>();
24-
});
25-
}
62+
#if (RequiresHttps)
63+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
64+
app.UseHsts();
65+
}
66+
67+
app.UseHttpsRedirection();
68+
#else
2669
}
70+
71+
#endif
72+
app.UseStaticFiles();
73+
app.UseRouting();
74+
75+
#if (IndividualLocalAuth)
76+
app.UseAuthentication();
77+
app.UseIdentityServer();
78+
#endif
79+
#if (!NoAuth)
80+
app.UseAuthorization();
81+
#endif
82+
83+
app.MapControllerRoute(
84+
name: "default",
85+
pattern: "{controller}/{action=Index}/{id?}");
86+
#if (IndividualLocalAuth)
87+
app.MapRazorPages();
88+
#endif
89+
90+
app.MapFallbackToFile("index.html");;
91+
92+
app.Run();

src/ProjectTemplates/Web.Spa.ProjectTemplates/content/Angular-CSharp/Startup.cs

Lines changed: 0 additions & 109 deletions
This file was deleted.
Lines changed: 85 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,92 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
2+
#if (IndividualLocalAuth)
3+
using Microsoft.AspNetCore.Authentication;
4+
#endif
5+
using Microsoft.AspNetCore.Builder;
56
using Microsoft.AspNetCore.Hosting;
7+
#if (IndividualLocalAuth)
8+
using Microsoft.AspNetCore.Identity;
9+
using Microsoft.AspNetCore.Identity.UI;
10+
#endif
11+
#if (IndividualLocalAuth)
12+
using Microsoft.EntityFrameworkCore;
13+
#endif
614
using Microsoft.Extensions.Configuration;
15+
using Microsoft.Extensions.DependencyInjection;
716
using Microsoft.Extensions.Hosting;
8-
using Microsoft.Extensions.Logging;
17+
#if (IndividualLocalAuth)
18+
using Company.WebApplication1.Data;
19+
using Company.WebApplication1.Models;
20+
#endif
921

10-
namespace Company.WebApplication1
22+
var builder = WebApplication.CreateBuilder(args);
23+
24+
// Add services to the container.
25+
#if (IndividualLocalAuth)
26+
var connectionString = Configuration.GetConnectionString("DefaultConnection");
27+
builder.Services.AddDbContext<ApplicationDbContext>(options =>
28+
#if (UseLocalDB)
29+
options.UseSqlServer(connectionString));
30+
#else
31+
options.UseSqlite(connectionString));
32+
#endif
33+
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
34+
35+
builder.Services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)
36+
.AddEntityFrameworkStores<ApplicationDbContext>();
37+
38+
builder.Services.AddIdentityServer()
39+
.AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
40+
41+
builder.Services.AddAuthentication()
42+
.AddIdentityServerJwt();
43+
#endif
44+
45+
builder.Services.AddControllersWithViews();
46+
#if (IndividualLocalAuth)
47+
builder.Services.AddRazorPages();
48+
#endif
49+
50+
var app = builder.Build();
51+
52+
// Configure the HTTP request pipeline.
53+
if (app.Environment.IsDevelopment())
54+
{
55+
app.UseDeveloperExceptionPage();
56+
#if (IndividualLocalAuth)
57+
app.UseMigrationsEndPoint();
58+
#endif
59+
}
60+
else
1161
{
12-
public class Program
13-
{
14-
public static void Main(string[] args)
15-
{
16-
CreateHostBuilder(args).Build().Run();
17-
}
18-
19-
public static IHostBuilder CreateHostBuilder(string[] args) =>
20-
Host.CreateDefaultBuilder(args)
21-
.ConfigureWebHostDefaults(webBuilder =>
22-
{
23-
webBuilder.UseStartup<Startup>();
24-
});
25-
}
62+
#if (RequiresHttps)
63+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
64+
app.UseHsts();
65+
}
66+
67+
app.UseHttpsRedirection();
68+
#else
2669
}
70+
71+
#endif
72+
app.UseStaticFiles();
73+
app.UseRouting();
74+
75+
#if (IndividualLocalAuth)
76+
app.UseAuthentication();
77+
app.UseIdentityServer();
78+
#endif
79+
#if (!NoAuth)
80+
app.UseAuthorization();
81+
#endif
82+
83+
app.MapControllerRoute(
84+
name: "default",
85+
pattern: "{controller}/{action=Index}/{id?}");
86+
#if (IndividualLocalAuth)
87+
app.MapRazorPages();
88+
#endif
89+
90+
app.MapFallbackToFile("index.html");;
91+
92+
app.Run();

0 commit comments

Comments
 (0)