// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, DbSeedData seeder)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            // use https connection
            app.UseHttpsRedirection();

            app.UseRouting();

            // use cors that is configured in ConfigureServices
            app.UseCors(MySpecificOrigin);

            // use authentication that is configured in ConfigureServices
            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            // seed data for development use
            seeder.EnsureSeedData();
        }
Example #2
0
        /// <summary>
        /// The Configure
        /// </summary>
        /// <param name="app">The app<see cref="IApplicationBuilder"/></param>
        /// <param name="env">The env<see cref="IHostingEnvironment"/></param>
        /// <param name="userManager">The userManager<see cref="UserManager{ApplicationUser}"/></param>
        /// <param name="roleManager">The roleManager<see cref="RoleManager{ApplicationRole}"/></param>
        /// <param name="context">The context<see cref="ApplicationDbContext"/></param>
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager <ApplicationUser> userManager, RoleManager <ApplicationRole> roleManager, ApplicationDbContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            try
            {
                using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope())
                {
                    serviceScope.ServiceProvider.GetService <ApplicationDbContext>().Database.EnsureCreated();
                }
            }
            catch (Exception ex)
            {
                var log = new Log();
                log.LogMessage(ex.Message + " " + ex.StackTrace + " " + ex.InnerException);
                context.Logger.Add(log);
                context.SaveChangesAsync().Wait();
            }

            // Use Forwarded Header to keep track of client info.
            app.UseForwardedHeaders();

            app.UseStaticFiles();

            // Use Authentication
            app.UseAuthentication();

            app.UseRouting();

            app.UseAuthorization();

            app.UseCors("CorsPolicy");

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();            // Map attribute-routed API controllers
                endpoints.MapDefaultControllerRoute(); // Map conventional MVC controllers using the default route
                endpoints.MapRazorPages();
            });

            // Seed Initial User
            DbSeedData.SeedData(userManager, roleManager, context).Wait();
        }
Example #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, DbSeedData seeder)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "ticketsystem_backend v1"));
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseCors(MySpecificOrigin);

            //app.UseCors(x => x
            //    .AllowAnyMethod()
            //    .AllowAnyHeader()
            //    .SetIsOriginAllowed(origin => true)
            //    .AllowCredentials());


            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();



                //endpoints.MapGet("/echo",
                //context => context.Response.WriteAsync("echo"))
                //.RequireCors(MySpecificOrigin);

                //endpoints.MapControllers()
                //         .RequireCors(MySpecificOrigin);

                //endpoints.MapGet("/echo2",
                //    context => context.Response.WriteAsync("echo2"));

                //endpoints.MapRazorPages();
            });
            seeder.EnsureSeedData();
        }
Example #4
0
 private static void CreateDbIfNotExists(IHost host)
 {
     using (var scope = host.Services.CreateScope())
     {
         var services = scope.ServiceProvider;
         var context  = services.GetRequiredService <Context>();
         DbSeedData.Initialize(context);
         //try
         //{
         //    var context = services.GetRequiredService<PCContext>();
         //    DbSeedData.Initialize(context);
         //}
         //catch (Exception ex)
         //{
         //    var logger = services.GetRequiredService<ILogger<Program>>();
         //    logger.LogError(ex, "An error occurred creating the DB.");
         //}
     }
 }
 public static void SeedTimeTrackingUsers(this ModelBuilder modelBuilder)
 {
     modelBuilder.Entity <TimeTrackingUser>().HasData(DbSeedData.TimeTrackingUserData());
 }