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);
        }
예제 #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app,
                              IWebHostEnvironment env,
                              IServiceProvider services
                              )
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
                app.UseHttpsRedirection();
            }

            app.UseStaticFiles();

            app.UseRouting();

            app.UseCors();

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

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });
            IdentitySeedData.SeedDatabase(services).Wait();
        }
예제 #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, IServiceProvider service)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

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

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

            app.UseSwagger();
            app.UseSwaggerUI(options =>
            {
                options.SwaggerEndpoint("v1/swagger.json", "Forum API");
            });

            IdentitySeedData.SeedDatabase(service).Wait();
        }
        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();
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider services)
        {
            if (env.IsDevelopment())
            {
                //app.UseDeveloperExceptionPage();
                app.UseExceptionHandler(builder =>
                {
                    builder.Run(async context =>
                    {
                        context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;

                        var error = context.Features.Get <IExceptionHandlerFeature>();

                        if (error != null)
                        {
                            context.Response.AddApplicationError(error.Error.Message);
                            await context.Response.WriteAsync(error.Error.Message);
                        }
                    });
                });
            }

            app.UseExceptionHandler(builder =>
            {
                builder.Run(async context =>
                {
                    context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;

                    var error = context.Features.Get <IExceptionHandlerFeature>();

                    if (error != null)
                    {
                        context.Response.AddApplicationError(error.Error.Message);
                        await context.Response.WriteAsync(error.Error.Message);
                    }
                });
            });

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthentication();

            app.UseAuthorization();

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

            app.UseSwagger();
            app.UseSwaggerUI(options =>
            {
                options.SwaggerEndpoint("/swagger/v1/swagger.json", "Fix IT Tracker API");
            });

            IdentitySeedData.SeedDatabase(services).Wait();
        }
예제 #6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider services)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

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

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

                endpoints.MapControllerRoute(
                    name: "angular_fallback",
                    pattern: "{target:regex(menu)}/{*catchall}",
                    defaults: new { controller = "Home", action = "Index" });

                endpoints.MapControllerRoute(
                    name: "angular_login",
                    pattern: "{target:regex(login)}/{*catchall}",
                    defaults: new { controller = "Home", action = "Index" });
            });

            app.UseSwagger();
            app.UseSwaggerUI(options => {
                options.SwaggerEndpoint("/swagger/v1/swagger.json",
                                        "SportsStore API");
            });

            app.UseSpa(spa => {
                string strategy = Configuration
                                  .GetValue <string>("DevTools:ConnectionStrategy");
                if (strategy == "proxy")
                {
                    spa.UseProxyToSpaDevelopmentServer("http://127.0.0.1:4200");
                }
                else if (strategy == "managed")
                {
                    spa.Options.SourcePath = "../ClientApp";
                    spa.UseAngularCliServer("start");
                }
            });

            IdentitySeedData.SeedDatabase(services).Wait();
        }
예제 #7
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env,
                              IdentityDataContext identityContext,
                              UserManager <IdentityUser> userManager,
                              RoleManager <IdentityRole> roleManager,
                              IAntiforgery antiforgery)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseSpaStaticFiles();
            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}/{action=Index}/{id?}");
            });

            app.UseSwagger();

            app.UseSwaggerUI(options =>
                             options.SwaggerEndpoint("/swagger/v1/swagger.json", "BooksStore API v1"));

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

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

            IdentitySeedData.SeedDatabase(identityContext,
                                          userManager, roleManager).GetAwaiter().GetResult();
        }
예제 #8
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);
            }
        }
예제 #9
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>());
        }
예제 #10
0
        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();
            //} else {
            //  app.UseExceptionHandler("/Home/Error");
            //}

            app.UseStaticFiles();
            app.UseSession();
            app.UseAuthentication();
            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);
            await IdentitySeedData.SeedDatabase(app);

//                 System.Console.WriteLine("Database Preparation Complete");
//                 System.Environment.Exit(0);
//             }
        }
예제 #11
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);
            }
        }
예제 #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();
     }
     //app.UseCors(builder => builder.WithOrigins(Configuration["ClientUrl"]).AllowAnyMethod().AllowCredentials().AllowAnyHeader());
     app.UseSession();
     app.UseAuthentication();
     app.UseCors("default");
     app.UseMvcWithDefaultRoute();
     using (var scope = app.ApplicationServices.CreateScope())
     {
         SeedData.SeedDatabase(scope.ServiceProvider.GetRequiredService <DataContext>());
         IdentitySeedData.SeedDatabase(scope.ServiceProvider).GetAwaiter().GetResult();
     }
 }
예제 #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, 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);
        }
예제 #14
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 services)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                app.UseHsts();
            }

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

            //adding authentication middleware (before the MVC middleware!)
            app.UseAuthentication();

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

            app.UseSpa(spa =>
            {
                // To learn more about options for serving an Angular SPA from ASP.NET Core,
                // see https://go.microsoft.com/fwlink/?linkid=864501

                spa.Options.SourcePath = "ClientApp";

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

            IdentitySeedData.SeedDatabase(services).Wait();
        }
예제 #15
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseStaticFiles();
            app.UseOpenApi();
            app.UseSwaggerUi3();
            app.UseHttpsRedirection();
            app.UseCors();
            app.UseRouting();
            app.UseAuthentication();
            app.UseAuthorization();

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

            app.UseSpa(spa =>
            {
                var strategy = Configuration.GetValue <string>("DevTools:ConnectionStrategy");
                if (strategy == "proxy")
                {
                    spa.UseProxyToSpaDevelopmentServer("http://localhost:4200");
                }
                else if (strategy == "managed")
                {
                    spa.Options.SourcePath = "../Webapp";
                    spa.UseAngularCliServer("start");
                }
            });

            IdentitySeedData.SeedDatabase(app).Wait();
        }
예제 #16
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env,
                              IServiceProvider services)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

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

            app.UseStaticFiles(new StaticFileOptions {
                RequestPath  = "/blazor",
                FileProvider = new PhysicalFileProvider(
                    Path.Combine(Directory.GetCurrentDirectory(),
                                 "../BlazorApp/wwwroot"))
            });

            app.UseSession();

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

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

                endpoints.MapControllerRoute(
                    name: "angular_fallback",
                    pattern: "{target:regex(admin|store|cart|checkout):nonfile}/{*catchall}",
                    defaults: new { controller = "Home", action = "Index" });

                endpoints.MapFallbackToClientSideBlazor <BlazorApp
                                                         .Startup>("blazor/{*path:nonfile}", "index.html");

                // endpoints.MapControllerRoute(
                //      name: "blazor_integration",
                //      pattern: "/blazor/{*path:nonfile}",
                //      defaults: new { controller = "Home", action = "Blazor"});

                endpoints.MapRazorPages();
            });

            app.Map("/blazor", opts =>
                    opts.UseClientSideBlazorFiles <BlazorApp.Startup>());

            app.UseClientSideBlazorFiles <BlazorApp.Startup>();

            app.UseSwagger();
            app.UseSwaggerUI(options => {
                options.SwaggerEndpoint("/swagger/v1/swagger.json",
                                        "SportsStore API");
            });

            app.UseSpa(spa => {
                string strategy = Configuration
                                  .GetValue <string>("DevTools:ConnectionStrategy");
                if (strategy == "proxy")
                {
                    spa.UseProxyToSpaDevelopmentServer("http://127.0.0.1:4200");
                }
                else if (strategy == "managed")
                {
                    spa.Options.SourcePath = "../ClientApp";
                    spa.UseAngularCliServer("start");
                }
            });

            SeedData.SeedDatabase(services.GetRequiredService <DataContext>());
            IdentitySeedData.SeedDatabase(services).Wait();
        }
예제 #17
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env,
                              IServiceProvider services)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            // app.UseHttpsRedirection();
            app.UseStaticFiles(new StaticFileOptions()
            {
                FileProvider = new PhysicalFileProvider(Path.Combine(
                                                            Directory.GetCurrentDirectory(),
                                                            @"Resources")),
                RequestPath = new PathString("/Resources")
            });

            app.UseSession();

            app.UseRouting();

            // app.UseCors(builder =>
            // {
            //     builder.WithOrigins("http://127.0.0.1:4200")
            //            .SetIsOriginAllowedToAllowWildcardSubdomains()
            //            .AllowAnyHeader()
            //            .AllowAnyMethod();
            // });

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

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

                endpoints.MapControllerRoute(
                    name: "angular_fallback",
                    pattern: "{target:regex(store|cart|checkout)}/{*catchall}",
                    defaults: new { controller = "Home", action = "Index" });

                endpoints.MapRazorPages();
            });

            app.UseSwagger();
            app.UseSwaggerUI(options =>
            {
                options.SwaggerEndpoint("/swagger/v1/swagger.json",
                                        "SportsStore API");
            });

            app.UseSpa(spa =>
            {
                string strategy = Configuration
                                  .GetValue <string>("DevTools:ConnectionStrategy");
                if (strategy == "proxy")
                {
                    spa.UseProxyToSpaDevelopmentServer("http://127.0.0.1:4200");
                }
                else if (strategy == "managed")
                {
                    spa.Options.SourcePath = "../ClientApp";
                    spa.UseAngularCliServer("start");
                }
            });

            SeedData.SeedDatabase(services.GetRequiredService <DataContext>());
            IdentitySeedData.SeedDatabase(services).Wait();
        }
예제 #18
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider serviceProvider)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();

            //	Enable sessions in the application.
            app.UseSession();

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

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

                //	Allowing direct navigation during development.
                //	Note:  if spaces are within regex(), then the pattern does NOT match.

                //	Note:  "nonfile" is required because the name of the file that will be requested
                //			when the dynamic module loaded is admin-admin-module.js
                //			and CARE MUST BE TAKEN not to direct requests for this file to MVC.
                endpoints.MapControllerRoute(
                    name: "angular_fallback",
                    pattern: "{target:regex(admin|store|cart|checkout):nonfile}/{*catchall}",
                    defaults: new { controller = "Home", action = "Index" });

                //	This is the recommended place to use SignalR MapHub<>.
                //	TypeScript will use the relative path specified here.
                //	e.g. const signalRHubUrl = "/chat";
                //    this.hubConnection = new HubConnectionBuilder()
                //      .configureLogging(LogLevel.Information)
                //      .withUrl(signalRHubUrl)
                //      .build();
                endpoints.MapHub <ChatHub>("/chat");
            });

            //	Prepare WebSockets.
            var webSocketOptions = new WebSocketOptions()
            {
                KeepAliveInterval = TimeSpan.FromSeconds(120),
                ReceiveBufferSize = 4 * 1024
            };

            app.UseWebSockets(webSocketOptions);

            app.UseSwagger();
            app.UseSwaggerUI(options =>
            {
                options.SwaggerEndpoint("/swagger/v1/swagger.json", "SportsStore API");
            });

            app.UseSpa(spa =>
            {
                string strategy = Configuration.GetValue <string>("DevTools:ConnectionStrategy");

                if (strategy == "proxy")
                {
                    Uri angularServerUri = new Uri("http://127.0.0.1:4200");
                    spa.UseProxyToSpaDevelopmentServer(angularServerUri);
                }
                else if (strategy == "managed")
                {
                    spa.Options.SourcePath = "../ClientApp";

                    spa.UseAngularCliServer(npmScript: "start");
                }
                else
                {
                    //  Do nothing.
                }
            });

            //  Seed the database with initial data if it is empty.
            DataContext dataContext;

            dataContext = serviceProvider.GetRequiredService <DataContext>();
            SeedData.SeedDatabase(dataContext);

            //	Seed the identity database.
            //	Wait() ensures that the database context remains available while the database is seeded.
            IdentitySeedData.SeedDatabase(serviceProvider).Wait();
        }
예제 #19
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider services, IAntiforgery antiforgery, IHostApplicationLifetime lifetime)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles(
                //new StaticFileOptions
                //{
                //	RequestPath = "/blazor",
                //	FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "../BlazorApp/wwwroot"))
                //}
                );

            app.UseStaticFiles(
                new StaticFileOptions {
                RequestPath  = "",
                FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "./wwwroot/app"))
            }
                );
            app.UseSession();

            app.UseRouting();
            app.UseAuthentication();

            app.UseAuthorization();

            app.Use(nextDeligate => context => {
                string path         = context.Request.Path.Value;
                string[] directUrls = { "/admin", "/store", "/cart", "checkout" };
                if (path.StartsWith("/api") || string.Equals("/", path) || directUrls.Any(url => path.StartsWith(url)))
                {
                    var tokens = antiforgery.GetAndStoreTokens(context);
                    context.Response.Cookies.Append("XSRF-TOKEN",
                                                    tokens.RequestToken, new Microsoft.AspNetCore.Http.CookieOptions()
                    {
                        HttpOnly = false, Secure = false, IsEssential = true, SameSite = Microsoft.AspNetCore.Http.SameSiteMode.Strict
                    });
                }
                ;
                return(nextDeligate(context));
            });

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapControllerRoute(
                    name: "angular_fallback",
                    pattern: "{target:regex(admin|store|cart|checkout):nonfile}/{*catchall}",
                    defaults: new { controller = "Home", action = "Index" }
                    );
                endpoints.MapControllerRoute(name: "blazor_integration",
                                             pattern: "/blazor/{*path:nonfile}",
                                             defaults: new { controller = "Home", action = "Blazor" });
                //endpoints.MapFallbackToClientSideBlazor<BlazorApp.Startup>("blazor/{*path:nonfile}", "index.html");
                endpoints.MapRazorPages();
            });
            //app.UseSpa(spa => {
            //    spa.Options.SourcePath = "../ClientApp";
            //    spa.UseAngularCliServer("start");

            //});

            //app.Map("/blazor", opt => opt.UseClientSideBlazorFiles<BlazorApp.Startup>());
            app.UseClientSideBlazorFiles <BlazorApp.Startup>();
            //app.UseSwagger();
            //app.UseSwaggerUI(option=> {
            //    option.SwaggerEndpoint("/swagger/v1/swagger.json","SportsStore API");
            //});

            //app.UseSpa(spa=> {
            //    string strategy = Configuration
            //        .GetValue<string>("DevTools:ConnectionStrategy");
            //    if (strategy == "proxy")
            //    {
            //        spa.UseProxyToSpaDevelopmentServer("http://127.0.0.1:4200");
            //    }
            //    else if (strategy == "managed")
            //    {
            //        spa.Options.SourcePath = "../ClientApp";
            //        spa.UseAngularCliServer("start");
            //    }
            //});
            //SeedData.SeedDatabase(services.GetRequiredService<DataContext>());
            //IdentitySeedData.SeedDatabase(services).Wait();
            if ((Configuration["INITDB"] ?? "false") == "true")
            {
                System.Console.WriteLine("Preparing Database...");
                SeedData.SeedDatabase(services.GetRequiredService <DataContext>());
                IdentitySeedData.SeedDatabase(services).Wait();
                System.Console.WriteLine("Database Preparation Complete");
                lifetime.StopApplication();
            }
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env,
                              IServiceProvider services, IAntiforgery antiforgery,
                              IHostApplicationLifetime lifetime)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseSession();

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

            app.Use(nextDelegate => context => {
                string path         = context.Request.Path.Value;
                string[] directUrls = { "/admin", "/store", "/cart", "checkout" };
                if (path.StartsWith("/api") || string.Equals("/", path) ||
                    directUrls.Any(url => path.StartsWith(url)))
                {
                    var tokens = antiforgery.GetAndStoreTokens(context);

                    context.Response.Cookies.Append("XSRF-TOKEN",
                                                    tokens.RequestToken, new CookieOptions()
                    {
                        HttpOnly = false, Secure = false, IsEssential = true
                    });
                }
                return(nextDelegate(context));
            });

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

                endpoints.MapControllerRoute(
                    name: "angular_fallback",
                    pattern: "{target:regex(admin|store|cart|checkout):nonfile}/{*catchall}",
                    defaults: new { controller = "Home", action = "Index" });
            });

            if ((Configuration["INITDB"] ?? "false") == "true")
            {
                System.Console.WriteLine("Preparing Database...");
                SeedData.SeedDatabase(services.GetRequiredService <DataContext>());
                IdentitySeedData.SeedDatabase(services).Wait();
                System.Console.WriteLine("Database Preparation Complete");
                lifetime.StopApplication();
            }
        }