Esempio n. 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseRouting();
            app.UseStaticFiles();

            // global cors policy
            app.UseCors(x => x
                        .AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader());

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

            app.UseMiddleware <JwtMiddleware>();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });

            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "FBLA SocialApp API V1");
            });

            using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                var roleManager = serviceScope.ServiceProvider.GetRequiredService <RoleManager <ApplicationRole> >();
                var userManager = serviceScope.ServiceProvider.GetRequiredService <UserManager <ApplicationUser> >();

                // seed the AspNetRoles table
                var roleSeed = new ApplicationRoleSeed(roleManager);
                roleSeed.CreateRoles();

                // seed the AspNetUsers table
                var userSeed = new ApplicationUserSeed(userManager);
                userSeed.CreateAdminUser();
            }
        }
Esempio n. 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                var roleManager = serviceScope.ServiceProvider.GetRequiredService <RoleManager <ApplicationRole> >();
                var userManager = serviceScope.ServiceProvider.GetRequiredService <UserManager <ApplicationUser> >();

                // seed the AspNetRoles table
                var roleSeed = new ApplicationRoleSeed(roleManager);
                roleSeed.CreateRoles();

                // seed the AspNetUsers table
                var userSeed = new ApplicationUserSeed(userManager);
                userSeed.CreateAdminUser();
            }
        }
Esempio n. 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)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            if (env.IsProduction())
            {
                app.UseForwardedHeaders(new ForwardedHeadersOptions
                {
                    ForwardedHeaders = ForwardedHeaders.XForwardedProto
                });
            }

            app.UseRouting();
            app.UseStaticFiles();
            app.UseCookiePolicy(); // https://docs.microsoft.com/en-us/aspnet/core/security/samesite?view=aspnetcore-3.1
            app.UseAuthentication();
            app.UseAuthorization();

            // Set up hangfire capabilities
            var options = new DashboardOptions
            {
                Authorization = new[] { new HangfireAuthorizationFilter() }
            };

            app.UseHangfireDashboard("/hangfire", options);
            app.UseHangfireServer();

            RecurringJob.AddOrUpdate <IGenerateTranscripts>(
                generator => generator.Execute(), Cron.Daily);

            BackgroundJob.Enqueue <IStudentDataImporter>(
                generator => generator.Execute());

            //BackgroundJob.Enqueue<IEmailQueue>(
            //    queue => queue.SendMail("*****@*****.**", "Test Message", "this is a scholarship email test.. did you get this?"));
            //BackgroundJob.Enqueue<ICreateApplicationPackage>(queue => queue.Execute());

            // If you want to run the job immediately

            /*
             * BackgroundJob.Enqueue<IGenerateTranscripts>(
             *  generator => generator.Execute());
             */

            // Set up App_Data directory
            // set
            var baseDir = env.ContentRootPath;

            AppDomain.CurrentDomain.SetData("DataDirectory", Path.Combine(baseDir, "App_Data"));

            app.UseStatusCodePagesWithRedirects("/error/{0}");
            app.UseAnalyticsLogger(); // Custom middleware

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    "default",
                    "{controller=Home}/{action=Index}/{id?}");

                endpoints.MapControllerRoute(
                    "securedownload",
                    "{controller=SecureDownload}/{id?}/{filename?}",
                    new { controller = "SecureDownload", action = "Download" }
                    );
            });

            using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                var roleManager = serviceScope.ServiceProvider.GetRequiredService <RoleManager <ApplicationRole> >();
                var userManager = serviceScope.ServiceProvider.GetRequiredService <UserManager <ApplicationUser> >();
                var dbContext   = serviceScope.ServiceProvider.GetRequiredService <ApplicationDbContext>();

                // seed the AspNetRoles table
                var roleSeed = new ApplicationRoleSeed(roleManager);
                roleSeed.CreateRoles();

                // seed the AspNetUsers table
                var userSeed = new ApplicationUserSeed(userManager, dbContext);
                userSeed.CreateAdminUser();

                var dbSeed = new ApplicationDbSeed(dbContext);
                dbSeed.SeedDatabase();
            }

            app.UseSmidge(bundles =>
            {
                bundles.CreateCss("scholarship-application-css",
                                  "~/lib/bootstrap/dist/css/bootstrap.css",
                                  "~/lib/font-awesome/css/font-awesome.css",
                                  "~/css/animate.css",
                                  "~/css/style.css",
                                  "~/css/site.css",
                                  "~/lib/heart/heart.css");

                // Libraries
                bundles.CreateJs("scholarship-js-libraries",
                                 "~/lib/jquery/dist/jquery.js",
                                 "~/lib/jquery-ui/jquery-ui.js",
                                 "~/lib/Popper/popper.js",
                                 "~/lib/bootstrap/dist/js/bootstrap.js"
                                 );

                // Custom scripts
                bundles.CreateJs("scholarship-js-custom",
                                 "~/js/site.js");

                // Inspinia scripts
                bundles.CreateJs("scholarship-js-inspinia",
                                 "~/lib/metisMenu/dist/jquery.metisMenu.js",
                                 "~/lib/slimScroll/jquery.slimscroll.js",
                                 "~/lib/pace/pace.js",
                                 "~/js/script.js");
            });
        }