diff --git a/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/Angular-CSharp/Startup.cs b/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/Angular-CSharp/Startup.cs index b5d6e749b978..d6e4a775ccde 100644 --- a/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/Angular-CSharp/Startup.cs +++ b/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/Angular-CSharp/Startup.cs @@ -36,13 +36,13 @@ public void ConfigureServices(IServiceCollection services) { #if (IndividualLocalAuth) services.AddDbContext(options => - #if (UseLocalDB) +#if (UseLocalDB) options.UseSqlServer( Configuration.GetConnectionString("DefaultConnection"))); - #else +#else options.UseSqlite( Configuration.GetConnectionString("DefaultConnection"))); - #endif +#endif services.AddDefaultIdentity() .AddEntityFrameworkStores(); @@ -53,8 +53,10 @@ public void ConfigureServices(IServiceCollection services) services.AddAuthentication() .AddIdentityServerJwt(); #endif - services.AddMvc(options => options.EnableEndpointRouting = false); - + services.AddControllersWithViews(); +#if (IndividualLocalAuth) + services.AddRazorPages(); +#endif // In production, the Angular files will be served from this directory services.AddSpaStaticFiles(configuration => { @@ -87,17 +89,24 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) #endif app.UseStaticFiles(); app.UseSpaStaticFiles(); -#if (IndividualLocalAuth) + app.UseRouting(); + +#if (IndividualLocalAuth) app.UseAuthentication(); app.UseIdentityServer(); #endif - - app.UseMvc(routes => +#if (!NoAuth) + app.UseAuthorization(); +#endif + app.UseEndpoints(endpoints => { - routes.MapRoute( + endpoints.MapControllerRoute( name: "default", - template: "{controller}/{action=Index}/{id?}"); + pattern: "{controller}/{action=Index}/{id?}"); +#if (IndividualLocalAuth) + endpoints.MapRazorPages(); +#endif }); app.UseSpa(spa => diff --git a/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/React-CSharp/Startup.cs b/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/React-CSharp/Startup.cs index 2303f02e1b0f..13319df968bf 100644 --- a/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/React-CSharp/Startup.cs +++ b/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/React-CSharp/Startup.cs @@ -36,13 +36,13 @@ public void ConfigureServices(IServiceCollection services) { #if (IndividualLocalAuth) services.AddDbContext(options => - #if (UseLocalDB) +#if (UseLocalDB) options.UseSqlServer( Configuration.GetConnectionString("DefaultConnection"))); - #else +#else options.UseSqlite( Configuration.GetConnectionString("DefaultConnection"))); - #endif +#endif services.AddDefaultIdentity() .AddEntityFrameworkStores(); @@ -53,7 +53,11 @@ public void ConfigureServices(IServiceCollection services) services.AddAuthentication() .AddIdentityServerJwt(); #endif - services.AddMvc(options => options.EnableEndpointRouting = false); + + services.AddControllersWithViews(); +#if (IndividualLocalAuth) + services.AddRazorPages(); +#endif // In production, the React files will be served from this directory services.AddSpaStaticFiles(configuration => @@ -87,17 +91,24 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) #endif app.UseStaticFiles(); app.UseSpaStaticFiles(); -#if (IndividualLocalAuth) + app.UseRouting(); + +#if (IndividualLocalAuth) app.UseAuthentication(); app.UseIdentityServer(); #endif - - app.UseMvc(routes => +#if (!NoAuth) + app.UseAuthorization(); +#endif + app.UseEndpoints(endpoints => { - routes.MapRoute( + endpoints.MapControllerRoute( name: "default", - template: "{controller}/{action=Index}/{id?}"); + pattern: "{controller}/{action=Index}/{id?}"); +#if (IndividualLocalAuth) + endpoints.MapRazorPages(); +#endif }); app.UseSpa(spa => diff --git a/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/ReactRedux-CSharp/Startup.cs b/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/ReactRedux-CSharp/Startup.cs index 620d39f9af98..2281a7ed77e4 100644 --- a/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/ReactRedux-CSharp/Startup.cs +++ b/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/ReactRedux-CSharp/Startup.cs @@ -23,7 +23,7 @@ public Startup(IConfiguration configuration) // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - services.AddMvc(options => options.EnableEndpointRouting = false); + services.AddControllersWithViews(); // In production, the React files will be served from this directory services.AddSpaStaticFiles(configuration => @@ -55,11 +55,13 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) app.UseStaticFiles(); app.UseSpaStaticFiles(); - app.UseMvc(routes => + app.UseRouting(); + + app.UseEndpoints(endpoints => { - routes.MapRoute( + endpoints.MapControllerRoute( name: "default", - template: "{controller}/{action=Index}/{id?}"); + pattern: "{controller}/{action=Index}/{id?}"); }); app.UseSpa(spa =>