-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Endpoint routing in SPA templates #11621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3505acf
ca03388
9e372ff
6fe2b8e
7af00e7
9369da8
d8874a5
2bb5b04
0c96d37
b6476d3
db6aa55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,13 +36,13 @@ public void ConfigureServices(IServiceCollection services) | |
{ | ||
#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 @@ 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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think authorization should only get included when you aren't doing any authentication. |
||
#endif | ||
app.UseEndpoints(endpoints => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should also change to be similar to the other templates in |
||
{ | ||
routes.MapRoute( | ||
endpoints.MapControllerRoute( | ||
name: "default", | ||
template: "{controller}/{action=Index}/{id?}"); | ||
pattern: "{controller}/{action=Index}/{id?}"); | ||
#if (IndividualLocalAuth) | ||
endpoints.MapRazorPages(); | ||
#endif | ||
}); | ||
|
||
app.UseSpa(spa => | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,13 +36,13 @@ public void ConfigureServices(IServiceCollection services) | |
{ | ||
#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 @@ 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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
#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 => | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have
UseRouting()
above it, andUseAuthorization()
after it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With endpoint routing, the auth is handled by middleware now, so the authN/AuthZ middleware sit in between
UseRouting
andUseEndpoints