From 4b6e560e6dae6b9d1d45a33eba62382069646414 Mon Sep 17 00:00:00 2001 From: surtur Date: Mon, 28 Dec 2020 14:36:36 +0100 Subject: [PATCH] chore: replace legacy routing code with proper 3.1 --- Startup.cs | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/Startup.cs b/Startup.cs index 59d5c2c..6f45b27 100644 --- a/Startup.cs +++ b/Startup.cs @@ -35,11 +35,9 @@ namespace pwt_0x01_ng options.HttpOnly = HttpOnlyPolicy.Always; options.Secure = CookieSecurePolicy.Always; }); - services.Configure(options => { - /* necessary due to a switch to 3.1 */ - options.EnableEndpointRouting = false; - }); + services.AddControllersWithViews(); + services.AddRazorPages(); var connectionString = Environment.GetEnvironmentVariable("DB_CONNECTION_STRING"); services.AddDbContext(options => @@ -64,19 +62,23 @@ namespace pwt_0x01_ng app.UseExceptionHandler("/Home/Error"); } + app.UseRouting(); + app.UseEndpoints(endpoints => + { + endpoints.MapRazorPages(); + endpoints.MapControllerRoute( + name: "areas", + pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}" + ); + endpoints.MapControllerRoute( + name: "default", + pattern: "{controller=Home}/{action=Index}/{id?}" + ); + }); + app.UseStaticFiles(); app.UseCookiePolicy(); - app.UseMvc(routes => - { - routes.MapRoute( - name: "areas", - template: "{area:exists}/{controller=Home}/{action=Index}/{id?}" - ); - routes.MapRoute( - name: "default", - template: "{controller=Home}/{action=Index}/{id?}"); - }); } } }