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:
parent
a3b5434b8b
commit
3a590b4324
|
|
@ -36,13 +36,13 @@ namespace Company.WebApplication1
|
||||||
{
|
{
|
||||||
#if (IndividualLocalAuth)
|
#if (IndividualLocalAuth)
|
||||||
services.AddDbContext<ApplicationDbContext>(options =>
|
services.AddDbContext<ApplicationDbContext>(options =>
|
||||||
#if (UseLocalDB)
|
#if (UseLocalDB)
|
||||||
options.UseSqlServer(
|
options.UseSqlServer(
|
||||||
Configuration.GetConnectionString("DefaultConnection")));
|
Configuration.GetConnectionString("DefaultConnection")));
|
||||||
#else
|
#else
|
||||||
options.UseSqlite(
|
options.UseSqlite(
|
||||||
Configuration.GetConnectionString("DefaultConnection")));
|
Configuration.GetConnectionString("DefaultConnection")));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
services.AddDefaultIdentity<ApplicationUser>()
|
services.AddDefaultIdentity<ApplicationUser>()
|
||||||
.AddEntityFrameworkStores<ApplicationDbContext>();
|
.AddEntityFrameworkStores<ApplicationDbContext>();
|
||||||
|
|
@ -53,8 +53,10 @@ namespace Company.WebApplication1
|
||||||
services.AddAuthentication()
|
services.AddAuthentication()
|
||||||
.AddIdentityServerJwt();
|
.AddIdentityServerJwt();
|
||||||
#endif
|
#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
|
// In production, the Angular files will be served from this directory
|
||||||
services.AddSpaStaticFiles(configuration =>
|
services.AddSpaStaticFiles(configuration =>
|
||||||
{
|
{
|
||||||
|
|
@ -87,17 +89,24 @@ namespace Company.WebApplication1
|
||||||
#endif
|
#endif
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
app.UseSpaStaticFiles();
|
app.UseSpaStaticFiles();
|
||||||
#if (IndividualLocalAuth)
|
|
||||||
|
|
||||||
|
app.UseRouting();
|
||||||
|
|
||||||
|
#if (IndividualLocalAuth)
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseIdentityServer();
|
app.UseIdentityServer();
|
||||||
#endif
|
#endif
|
||||||
|
#if (!NoAuth)
|
||||||
app.UseMvc(routes =>
|
app.UseAuthorization();
|
||||||
|
#endif
|
||||||
|
app.UseEndpoints(endpoints =>
|
||||||
{
|
{
|
||||||
routes.MapRoute(
|
endpoints.MapControllerRoute(
|
||||||
name: "default",
|
name: "default",
|
||||||
template: "{controller}/{action=Index}/{id?}");
|
pattern: "{controller}/{action=Index}/{id?}");
|
||||||
|
#if (IndividualLocalAuth)
|
||||||
|
endpoints.MapRazorPages();
|
||||||
|
#endif
|
||||||
});
|
});
|
||||||
|
|
||||||
app.UseSpa(spa =>
|
app.UseSpa(spa =>
|
||||||
|
|
|
||||||
|
|
@ -36,13 +36,13 @@ namespace Company.WebApplication1
|
||||||
{
|
{
|
||||||
#if (IndividualLocalAuth)
|
#if (IndividualLocalAuth)
|
||||||
services.AddDbContext<ApplicationDbContext>(options =>
|
services.AddDbContext<ApplicationDbContext>(options =>
|
||||||
#if (UseLocalDB)
|
#if (UseLocalDB)
|
||||||
options.UseSqlServer(
|
options.UseSqlServer(
|
||||||
Configuration.GetConnectionString("DefaultConnection")));
|
Configuration.GetConnectionString("DefaultConnection")));
|
||||||
#else
|
#else
|
||||||
options.UseSqlite(
|
options.UseSqlite(
|
||||||
Configuration.GetConnectionString("DefaultConnection")));
|
Configuration.GetConnectionString("DefaultConnection")));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
services.AddDefaultIdentity<ApplicationUser>()
|
services.AddDefaultIdentity<ApplicationUser>()
|
||||||
.AddEntityFrameworkStores<ApplicationDbContext>();
|
.AddEntityFrameworkStores<ApplicationDbContext>();
|
||||||
|
|
@ -53,7 +53,11 @@ namespace Company.WebApplication1
|
||||||
services.AddAuthentication()
|
services.AddAuthentication()
|
||||||
.AddIdentityServerJwt();
|
.AddIdentityServerJwt();
|
||||||
#endif
|
#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
|
// In production, the React files will be served from this directory
|
||||||
services.AddSpaStaticFiles(configuration =>
|
services.AddSpaStaticFiles(configuration =>
|
||||||
|
|
@ -87,17 +91,24 @@ namespace Company.WebApplication1
|
||||||
#endif
|
#endif
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
app.UseSpaStaticFiles();
|
app.UseSpaStaticFiles();
|
||||||
#if (IndividualLocalAuth)
|
|
||||||
|
|
||||||
|
app.UseRouting();
|
||||||
|
|
||||||
|
#if (IndividualLocalAuth)
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseIdentityServer();
|
app.UseIdentityServer();
|
||||||
#endif
|
#endif
|
||||||
|
#if (!NoAuth)
|
||||||
app.UseMvc(routes =>
|
app.UseAuthorization();
|
||||||
|
#endif
|
||||||
|
app.UseEndpoints(endpoints =>
|
||||||
{
|
{
|
||||||
routes.MapRoute(
|
endpoints.MapControllerRoute(
|
||||||
name: "default",
|
name: "default",
|
||||||
template: "{controller}/{action=Index}/{id?}");
|
pattern: "{controller}/{action=Index}/{id?}");
|
||||||
|
#if (IndividualLocalAuth)
|
||||||
|
endpoints.MapRazorPages();
|
||||||
|
#endif
|
||||||
});
|
});
|
||||||
|
|
||||||
app.UseSpa(spa =>
|
app.UseSpa(spa =>
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ namespace Company.WebApplication1
|
||||||
// This method gets called by the runtime. Use this method to add services to the container.
|
// This method gets called by the runtime. Use this method to add services to the container.
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddMvc(options => options.EnableEndpointRouting = false);
|
services.AddControllersWithViews();
|
||||||
|
|
||||||
// In production, the React files will be served from this directory
|
// In production, the React files will be served from this directory
|
||||||
services.AddSpaStaticFiles(configuration =>
|
services.AddSpaStaticFiles(configuration =>
|
||||||
|
|
@ -55,11 +55,13 @@ namespace Company.WebApplication1
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
app.UseSpaStaticFiles();
|
app.UseSpaStaticFiles();
|
||||||
|
|
||||||
app.UseMvc(routes =>
|
app.UseRouting();
|
||||||
|
|
||||||
|
app.UseEndpoints(endpoints =>
|
||||||
{
|
{
|
||||||
routes.MapRoute(
|
endpoints.MapControllerRoute(
|
||||||
name: "default",
|
name: "default",
|
||||||
template: "{controller}/{action=Index}/{id?}");
|
pattern: "{controller}/{action=Index}/{id?}");
|
||||||
});
|
});
|
||||||
|
|
||||||
app.UseSpa(spa =>
|
app.UseSpa(spa =>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue