diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/ApplicationDbContext.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/ApplicationDbContext.cs new file mode 100644 index 0000000000..a33a15e3e9 --- /dev/null +++ b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/ApplicationDbContext.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Microsoft.AspNetCore.Identity.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; + +namespace Company.WebApplication1.Data +{ + public class ApplicationDbContext : IdentityDbContext + { + public ApplicationDbContext(DbContextOptions options) + : base(options) + { + } + } +} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs index 30761bb5db..8d505f4d0d 100644 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs +++ b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; #endif -using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; @@ -12,7 +11,7 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace Company.WebApplication1.Data.Migrations { - [DbContext(typeof(IdentityDbContext))] + [DbContext(typeof(ApplicationDbContext))] [Migration("00000000000000_CreateIdentitySchema")] partial class CreateIdentitySchema { diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/Migrations/IdentityDbContextModelSnapshot.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/Migrations/ApplicationDbContextModelSnapshot.cs similarity index 98% rename from src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/Migrations/IdentityDbContextModelSnapshot.cs rename to src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/Migrations/ApplicationDbContextModelSnapshot.cs index 06ce89d3a6..4c72ab166e 100644 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/Migrations/IdentityDbContextModelSnapshot.cs +++ b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/Migrations/ApplicationDbContextModelSnapshot.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; #endif -using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; @@ -12,8 +11,8 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace Company.WebApplication1.Data.Migrations { - [DbContext(typeof(IdentityDbContext))] - partial class IdentityDbContextModelSnapshot : ModelSnapshot + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot { protected override void BuildModel(ModelBuilder modelBuilder) { diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Startup.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Startup.cs index 9f8e55d6ae..0dec781d33 100644 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Startup.cs +++ b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Startup.cs @@ -13,7 +13,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Builder; #if (IndividualLocalAuth) using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Identity.EntityFrameworkCore; #endif #if (OrganizationalAuth || IndividualAuth) using Microsoft.AspNetCore.Http; @@ -26,6 +25,7 @@ using Microsoft.AspNetCore.Mvc.Authorization; #endif #if (IndividualLocalAuth) using Microsoft.EntityFrameworkCore; +using Company.WebApplication1.Data; #endif using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -57,20 +57,16 @@ namespace Company.WebApplication1 }); #if (IndividualLocalAuth) - services.AddDbContext(options => - #if (UseLocalDB) + services.AddDbContext(options => +#if (UseLocalDB) options.UseSqlServer( - Configuration.GetConnectionString("DefaultConnection"), - sqlOptions => sqlOptions.MigrationsAssembly("Company.WebApplication1") - )); - #else + Configuration.GetConnectionString("DefaultConnection"))); +#else options.UseSqlite( - Configuration.GetConnectionString("DefaultConnection"), - sqlOptions => sqlOptions.MigrationsAssembly("Company.WebApplication1") - )); - #endif + Configuration.GetConnectionString("DefaultConnection"))); +#endif services.AddIdentity(options => options.Stores.MaxLengthForKeys = 128) - .AddEntityFrameworkStores() + .AddEntityFrameworkStores() .AddDefaultUI() .AddDefaultTokenProviders(); @@ -80,24 +76,15 @@ namespace Company.WebApplication1 sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme; }) - #if (OrganizationalAuth) +#if (OrganizationalAuth) .AddAzureAd(options => Configuration.Bind("AzureAd", options)) - #elif (IndividualB2CAuth) +#elif (IndividualB2CAuth) .AddAzureAdB2C(options => Configuration.Bind("AzureAdB2C", options)) - #endif +#endif .AddCookie(); #endif -#if (IndividualLocalAuth) - services.AddMvc() - .AddRazorPagesOptions(options => - { - options.Conventions.AuthorizeFolder("/Account/Manage"); - options.Conventions.AuthorizePage("/Account/Logout"); - }) - .SetCompatibilityVersion(CompatibilityVersion.Version_2_1); - -#elif (OrganizationalAuth) +#if (OrganizationalAuth) services.AddMvc(options => { var policy = new AuthorizationPolicyBuilder() diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Data/ApplicationDbContext.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Data/ApplicationDbContext.cs new file mode 100644 index 0000000000..a33a15e3e9 --- /dev/null +++ b/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Data/ApplicationDbContext.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Microsoft.AspNetCore.Identity.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; + +namespace Company.WebApplication1.Data +{ + public class ApplicationDbContext : IdentityDbContext + { + public ApplicationDbContext(DbContextOptions options) + : base(options) + { + } + } +} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs index 30761bb5db..8d505f4d0d 100644 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs +++ b/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; #endif -using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; @@ -12,7 +11,7 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace Company.WebApplication1.Data.Migrations { - [DbContext(typeof(IdentityDbContext))] + [DbContext(typeof(ApplicationDbContext))] [Migration("00000000000000_CreateIdentitySchema")] partial class CreateIdentitySchema { diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Data/Migrations/IdentityDbContextModelSnapshot.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Data/Migrations/ApplicationDbContextModelSnapshot.cs similarity index 98% rename from src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Data/Migrations/IdentityDbContextModelSnapshot.cs rename to src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Data/Migrations/ApplicationDbContextModelSnapshot.cs index 06ce89d3a6..4c72ab166e 100644 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Data/Migrations/IdentityDbContextModelSnapshot.cs +++ b/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Data/Migrations/ApplicationDbContextModelSnapshot.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; #endif -using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; @@ -12,8 +11,8 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace Company.WebApplication1.Data.Migrations { - [DbContext(typeof(IdentityDbContext))] - partial class IdentityDbContextModelSnapshot : ModelSnapshot + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot { protected override void BuildModel(ModelBuilder modelBuilder) { diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Startup.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Startup.cs index bf2ef66e3c..e2e7351073 100644 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Startup.cs +++ b/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Startup.cs @@ -10,13 +10,13 @@ using Microsoft.AspNetCore.Authentication.OpenIdConnect; using Microsoft.AspNetCore.Builder; #if (IndividualLocalAuth) using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Identity.EntityFrameworkCore; #endif using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.Mvc; #if (IndividualLocalAuth) using Microsoft.EntityFrameworkCore; +using Company.WebApplication1.Data; #endif using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -42,21 +42,17 @@ namespace Company.WebApplication1 public void ConfigureServices(IServiceCollection services) { #if (IndividualLocalAuth) - services.AddDbContext(options => + services.AddDbContext(options => #if (UseLocalDB) options.UseSqlServer( - Configuration.GetConnectionString("DefaultConnection"), - sqlOptions => sqlOptions.MigrationsAssembly("Company.WebApplication1") - )); + Configuration.GetConnectionString("DefaultConnection"))); #else options.UseSqlite( - Configuration.GetConnectionString("DefaultConnection"), - sqlOptions => sqlOptions.MigrationsAssembly("Company.WebApplication1") - )); + Configuration.GetConnectionString("DefaultConnection"))); #endif services.AddIdentity(options => options.Stores.MaxLengthForKeys = 128) - .AddEntityFrameworkStores() + .AddEntityFrameworkStores() .AddDefaultUI() .AddDefaultTokenProviders();