Endpoint routing in SPA templates (#11621)

* Endpoint routing in SPA templates

* Revert "More doc comment additions"

This reverts commit ef2c042ec73f221a07d369e0c5f9ddd22298a632.

* PR feedback

* PR feedback

* Don't make the same mistake twice

* Resolve rebase problems

* Remove missing variable

* MapRazorPages

* Conditionalize

* Use variables that exist

* Fix variable names
This commit is contained in:
Ryan Brandenburg 2019-07-20 00:21:02 -07:00 committed by Artak
parent a3b5434b8b
commit 3a590b4324
3 changed files with 45 additions and 23 deletions

View File

@ -36,13 +36,13 @@ namespace Company.WebApplication1
{
#if (IndividualLocalAuth)
services.AddDbContext<ApplicationDbContext>(options =>
#if (UseLocalDB)
#if (UseLocalDB)
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
#else
#else
options.UseSqlite(
Configuration.GetConnectionString("DefaultConnection")));
#endif
#endif
services.AddDefaultIdentity<ApplicationUser>()
.AddEntityFrameworkStores<ApplicationDbContext>();
@ -53,8 +53,10 @@ namespace Company.WebApplication1
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 @@ namespace Company.WebApplication1
#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 =>

View File

@ -36,13 +36,13 @@ namespace Company.WebApplication1
{
#if (IndividualLocalAuth)
services.AddDbContext<ApplicationDbContext>(options =>
#if (UseLocalDB)
#if (UseLocalDB)
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
#else
#else
options.UseSqlite(
Configuration.GetConnectionString("DefaultConnection")));
#endif
#endif
services.AddDefaultIdentity<ApplicationUser>()
.AddEntityFrameworkStores<ApplicationDbContext>();
@ -53,7 +53,11 @@ namespace Company.WebApplication1
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 @@ namespace Company.WebApplication1
#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 =>

View File

@ -23,7 +23,7 @@ namespace Company.WebApplication1
// 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 @@ namespace Company.WebApplication1
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 =>