public void Configure(IApplicationBuilder app,
                              IHostingEnvironment env, DataContext context,
                              IdentityDataContext identityContext,
                              UserManager <IdentityUser> userManager,
                              RoleManager <IdentityRole> roleManager)
        {
            app.UseDeveloperExceptionPage();
            app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions {
                HotModuleReplacement = true
            });

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

                routes.MapSpaFallbackRoute("angular-fallback",
                                           new { controller = "Home", action = "Index" });
            });


            SeedData.SeedDatabase(context);
            IdentitySeedData.SeedDatabase(identityContext,
                                          userManager, roleManager).GetAwaiter().GetResult();
        }
        public void Configure(IApplicationBuilder app,
                              IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            app.UseDeveloperExceptionPage();
            app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions {
                HotModuleReplacement = true
            });

            app.UseStaticFiles();
            app.UseSession();
            app.UseIdentity();

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

                routes.MapSpaFallbackRoute("angular-fallback",
                                           new { controller = "Home", action = "Index" });
            });

            SeedData.SeedDatabase(app.ApplicationServices
                                  .GetRequiredService <DataContext>());
            IdentitySeedData.SeedDatabase(app);
        }
示例#3
0
        public async Task ConfigureAsync(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IAntiforgery antiforgery)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseStatusCodePages();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                app.UseHsts();
            }

            app.UseSession();
            app.UseAuthentication();
            app.UseStaticFiles();
            app.UseSpaStaticFiles();

            app.Use(nextDelegate => context =>
            {
                if (context.Request.Path.StartsWithSegments("/api") || context.Request.Path.StartsWithSegments("/"))
                {
                    context.Response.Cookies.Append("XSRF-TOKEN", antiforgery.GetAndStoreTokens(context).RequestToken);
                }
                return(nextDelegate(context));
            });

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

                //routes.MapSpaFallbackRoute("angular-fallback", new { controller="Home", action="Index" })
            });

            app.UseSpa(spa =>
            {
                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseAngularCliServer(npmScript: "start");
                }
            });

            if ((Configuration["INITDB"] ?? "false") == "true")
            {
                System.Console.WriteLine("Preparing Database...");
                SeedData.SeedDatabase(app.ApplicationServices
                                      .GetRequiredService <DataContext>());
                await IdentitySeedData.SeedDatabase(app);

                System.Console.WriteLine("Database Preparation Complete");
                System.Environment.Exit(0);
            }
        }
示例#4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IdentitySeedData seedData, IAntiforgery antiForgery, IServiceProvider serviceProvider)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            app.UseDeveloperExceptionPage();
            app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
            {
                HotModuleReplacement         = true,
                HotModuleReplacementEndpoint = "/dist/__webpack_hmr"
            });

            app.UseStaticFiles();
            app.UseSession();
            app.UseAuthentication();

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

                routes.MapSpaFallbackRoute("angular-fallback", new { controller = "Home", action = "Index" });
            });

            //if ((Configuration["INITDB"] ?? "false") == "true") {
            //  Console.WriteLine("Preparing Database...");
            SeedData.SeedDatabase(serviceProvider.GetRequiredService <DataContext>());
            await seedData.SeedDatabase(app);

            //await seedData.SeedDatabase();
            //  Console.WriteLine("Database Preparation Complete");
            //  Environment.Exit(0);
            //}

            app.Use(async(context, next) => {
                string path = context.Request.Path;
                if (context.Request.Path.StartsWithSegments("/api") || context.Request.Path.StartsWithSegments("/"))
                {
                    // XSRF-TOKEN used by angular in the $http if provided
                    var tokens = antiForgery.GetAndStoreTokens(context);
                    context.Response.Cookies.Append("XSRF-TOKEN", antiForgery.GetAndStoreTokens(context).RequestToken);
                    //tokens.RequestToken, new CookieOptions
                    //{
                    //  HttpOnly = false,
                    //  Secure = true
                    //}
                    //);
                }

                await next();
            });

            //SeedData.SeedDatabase(app.ApplicationServices.GetRequiredService<DataContext>());
        }
示例#5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IAntiforgery antiforgery)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            // app.UseDeveloperExceptionPage();
            // app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
            // {
            //     HotModuleReplacement = true
            // });

            //if (env.IsDevelopment()) {
            // app.UseDeveloperExceptionPage();
            // app.UseBrowserLink();
            //} else {
            // app.UseExceptionHandler("/Home/Error");
            //}

            app.UseStaticFiles();
            app.UseSession();
            app.UseIdentity();

            app.Use(nextDelegate => context =>
            {
                if (context.Request.Path.StartsWithSegments("/api") ||
                    context.Request.Path.StartsWithSegments("/"))
                {
                    context.Response.Cookies.Append("XSRF-TOKEN",
                                                    antiforgery.GetAndStoreTokens(context).RequestToken);
                }
                return(nextDelegate(context));
            });

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

                routes.MapSpaFallbackRoute("angular-fallback", new { controller = "Home", action = "Index" });
            });

            if ((Configuration["INITDB"] ?? "false") == "True")
            {
                System.Console.WriteLine("Preparing Database...");
                SeedData.SeedDatabase(app.ApplicationServices.GetRequiredService <DataContext>());
                await IdentitySeedData.SeedDatabase(app);

                System.Console.WriteLine("Database Preparation Complete");
                System.Environment.Exit(0);
            }
        }
示例#6
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                var contxt   = services.GetRequiredService <DataContext>();
                SeedData.SeedDatabase(contxt);
            }

            host.Run();
        }
示例#7
0
        public void Configure(IApplicationBuilder app,
                              IHostingEnvironment env, DataContext context,
                              IdentityDataContext identityContext,
                              UserManager <IdentityUser> userManager,
                              RoleManager <IdentityRole> roleManager,
                              IAntiforgery antiforgery)
        {
            //app.UseDeveloperExceptionPage();
            //app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions {
            //    HotModuleReplacement = true
            //});

            app.UseStaticFiles();
            app.UseSession();
            app.UseAuthentication();

            app.Use(nextDelegate => requestContext => {
                if (requestContext.Request.Path.StartsWithSegments("/api") ||
                    requestContext.Request.Path.StartsWithSegments("/"))
                {
                    requestContext.Response.Cookies.Append("XSRF-TOKEN",
                                                           antiforgery.GetAndStoreTokens(requestContext).RequestToken);
                }
                return(nextDelegate(requestContext));
            });

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

                routes.MapSpaFallbackRoute("angular-fallback",
                                           new { controller = "Home", action = "Index" });
            });

            if ((Configuration["INITDB"] ?? "false") == "true")
            {
                System.Console.WriteLine("Preparing Database...");
                context.Database.Migrate();
                SeedData.SeedDatabase(context);
                identityContext.Database.Migrate();
                IdentitySeedData.SeedDatabase(identityContext,
                                              userManager, roleManager).GetAwaiter().GetResult();
                System.Console.WriteLine("Database Preparation Complete");
                System.Environment.Exit(0);
            }
        }
        public void Configure(IApplicationBuilder app,
                              IHostingEnvironment env, DataContext context)
        {
            app.UseDeveloperExceptionPage();
            app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions {
                HotModuleReplacement = true
            });

            app.UseStaticFiles();

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

            SeedData.SeedDatabase(context);
        }
示例#9
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider)
        {
            app.UseDeveloperExceptionPage();
            app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions {
                HotModuleReplacement = true
            });
            app.UseStaticFiles();
            app.UseMvc(routes => {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}"
                    );
            });
            var context = serviceProvider.GetService <DataContext>();

            //SeedData.SeedDatabase(app.ApplicationServices.GetRequiredService<DataContext>());
            SeedData.SeedDatabase(context);
        }
示例#10
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            app.UseDeveloperExceptionPage();
            app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
            {
                HotModuleReplacement = true
            });

            // if (env.IsDevelopment())
            // {
            //     app.UseDeveloperExceptionPage();
            // }
            // else
            // {
            //     app.UseExceptionHandler("/Home/Error");
            // }

            app.UseStaticFiles();

            app.UseSession();

            // Use ASP.NET Core Identity
            app.UseIdentity();

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

                // Use angular fallback page for 404 requests (direct url access)
                routes.MapSpaFallbackRoute("angular-fallback", new { controller = "Home", action = "Index" });
            });

            // To create database if not exist and add test data
            SeedData.SeedDatabase(app.ApplicationServices.GetRequiredService <DataContext>());

            // To initialize identity databsae with test data
            IdentitySeedData.SeedDatabase(app);
        }
示例#11
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <DataContext>();
                    SeedData.SeedDatabase(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while migrating the database.");
                }
            }

            host.Run();
        }
示例#12
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseDeveloperExceptionPage();
            app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
            {
                HotModuleReplacement = true
            });
            //if (env.IsDevelopment()) {
            // app.UseDeveloperExceptionPage();
            // app.UseBrowserLink();
            //} else {
            // app.UseExceptionHandler("/Home/Error");
            //}

            app.UseStaticFiles();

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

                routes.MapSpaFallbackRoute("angular-fallback", new { controller = "Home", action = "Index" });
            });

            SeedData.SeedDatabase(app);
        }
示例#13
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, DataContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseSpaStaticFiles();

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

            app.UseSpa(spa =>
            {
                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseAngularCliServer(npmScript: "start");
                    //spa.UseProxyToSpaDevelopmentServer("http://localhost:4200");
                }
            });

            SeedData.SeedDatabase(context);
        }