From 0c9eda1f4a551df52f83c7a9b378b4ae8f02e0b5 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Tue, 11 Dec 2018 18:24:14 +1300 Subject: [PATCH] Update templates to use endpoint routing (#4500) --- .../content/EmptyWeb-CSharp/Startup.cs | 7 +++++-- .../content/EmptyWeb-FSharp/Startup.fs | 4 +++- .../content/RazorPagesWeb-CSharp/Startup.cs | 9 +++++++-- .../content/StarterWeb-CSharp/Startup.cs | 17 ++++++++++------- .../content/StarterWeb-FSharp/Startup.fs | 7 +++++-- .../content/WebApi-CSharp/Startup.cs | 10 +++++++--- .../content/WebApi-FSharp/Startup.fs | 6 +++++- 7 files changed, 42 insertions(+), 18 deletions(-) diff --git a/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/EmptyWeb-CSharp/Startup.cs b/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/EmptyWeb-CSharp/Startup.cs index d039a38a68..d9966c3204 100644 --- a/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/EmptyWeb-CSharp/Startup.cs +++ b/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/EmptyWeb-CSharp/Startup.cs @@ -25,9 +25,12 @@ namespace Company.WebApplication1 app.UseDeveloperExceptionPage(); } - app.Run(async (context) => + app.UseRouting(routes => { - await context.Response.WriteAsync("Hello World!"); + routes.MapGet("/", async context => + { + await context.Response.WriteAsync("Hello World!"); + }); }); } } diff --git a/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/EmptyWeb-FSharp/Startup.fs b/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/EmptyWeb-FSharp/Startup.fs index 2709a8aa3c..297d3debb8 100644 --- a/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/EmptyWeb-FSharp/Startup.fs +++ b/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/EmptyWeb-FSharp/Startup.fs @@ -18,4 +18,6 @@ type Startup() = if env.IsDevelopment() then app.UseDeveloperExceptionPage() |> ignore - app.Run(fun context -> context.Response.WriteAsync("Hello World!")) |> ignore \ No newline at end of file + app.UseRouting(fun routing -> + routing.MapGet("/", fun context -> context.Response.WriteAsync("Hello World!")) |> ignore + ) |> ignore \ No newline at end of file diff --git a/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Startup.cs b/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Startup.cs index c81aadf1e3..997c91f204 100644 --- a/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Startup.cs +++ b/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Startup.cs @@ -155,13 +155,18 @@ namespace Company.WebApplication1 #endif app.UseStaticFiles(); + + app.UseRouting(routes => + { + routes.MapApplication(); + }); + app.UseCookiePolicy(); #if (OrganizationalAuth || IndividualAuth) app.UseAuthentication(); - #endif - app.UseMvc(); + app.UseAuthorization(); } } } diff --git a/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Startup.cs b/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Startup.cs index a0014d92ae..943f163562 100644 --- a/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Startup.cs +++ b/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Startup.cs @@ -154,18 +154,21 @@ namespace Company.WebApplication1 #endif app.UseStaticFiles(); + + app.UseRouting(routes => + { + routes.MapApplication(); + routes.MapControllerRoute( + name: "default", + template: "{controller=Home}/{action=Index}/{id?}"); + }); + app.UseCookiePolicy(); #if (OrganizationalAuth || IndividualAuth) app.UseAuthentication(); - #endif - app.UseMvc(routes => - { - routes.MapRoute( - name: "default", - template: "{controller=Home}/{action=Index}/{id?}"); - }); + app.UseAuthorization(); } } } diff --git a/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-FSharp/Startup.fs b/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-FSharp/Startup.fs index c772867123..ff23471a93 100644 --- a/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-FSharp/Startup.fs +++ b/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-FSharp/Startup.fs @@ -40,10 +40,13 @@ type Startup private () = #endif app.UseStaticFiles() |> ignore - app.UseMvc(fun routes -> - routes.MapRoute( + app.UseRouting(fun routes -> + routes.MapApplication() |> ignore + routes.MapControllerRoute( name = "default", template = "{controller=Home}/{action=Index}/{id?}") |> ignore ) |> ignore + app.UseAuthorization() |> ignore + member val Configuration : IConfiguration = null with get, set diff --git a/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/WebApi-CSharp/Startup.cs b/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/WebApi-CSharp/Startup.cs index ca10c0a668..6cef403fee 100644 --- a/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/WebApi-CSharp/Startup.cs +++ b/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/WebApi-CSharp/Startup.cs @@ -61,13 +61,17 @@ namespace Company.WebApplication1 } app.UseHttpsRedirection(); -#else - #endif + + app.UseRouting(routes => + { + routes.MapApplication(); + }); + #if (OrganizationalAuth || IndividualAuth) app.UseAuthentication(); #endif - app.UseMvc(); + app.UseAuthorization(); } } } diff --git a/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/WebApi-FSharp/Startup.fs b/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/WebApi-FSharp/Startup.fs index 5a5554c5a2..6a1b3394d6 100644 --- a/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/WebApi-FSharp/Startup.fs +++ b/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/content/WebApi-FSharp/Startup.fs @@ -36,6 +36,10 @@ type Startup private () = #else #endif - app.UseMvc() |> ignore + app.UseRouting(fun routes -> + routes.MapApplication() |> ignore + ) |> ignore + + app.UseAuthorization() |> ignore member val Configuration : IConfiguration = null with get, set