コード例 #1
0
ファイル: Startup.cs プロジェクト: NPavl/SportsStore
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) //
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseStatusCodePages();
            }
            else
            {
                app.UseExceptionHandler("/Error");
            }

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

            app.UseMvc(routes =>
            {
                routes.MapRoute(name: "Error", template: "Error", defaults: new { controller = "Error", action = "Error" });

                routes.MapRoute
                (
                    name: null,
                    template: "{category}/Page{page:int}",
                    defaults: new { controller = "Product", action = "List" }
                );

                routes.MapRoute
                (
                    name: null,
                    template: "Page{page:int}",
                    defaults: new { controller = "Product", action = "List", page = 1 }
                );

                routes.MapRoute
                (
                    name: null,
                    template: "{category}",
                    defaults: new { controller = "Product", action = "List", page = 1 }
                );

                routes.MapRoute
                (
                    name: null,
                    template: "",
                    defaults: new { controller = "Product", action = "List", page = 1 }
                );

                routes.MapRoute
                (
                    name: null, template: "{controller}/{action}/{id?}");
            });

            using (var scope = app.ApplicationServices.CreateScope())
            {
                ApplicationDbContext context = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>();
                SeedData.EnsurePopulated(context);
            }
            IdentitySeedData.EnsurePopulated(app);
            // отключил в Program.cs Scope сервис следующй строкой :
            // .UseDefaultServiceProvider(options => options.ValidateScopes = false);
        }
コード例 #2
0
ファイル: Startup.cs プロジェクト: akazad13/archive-projects
        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();
        }
コード例 #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 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();
        }
コード例 #4
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();

            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(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.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.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();

            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();
            }
        }
コード例 #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, 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>());
        }
コード例 #6
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.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();
        }
コード例 #7
0
 public void Configure(IApplicationBuilder app, IHostingEnvironment env)
 {
     app.UseDeveloperExceptionPage();
     app.UseStaticFiles();
     app.UseAuthentication();
     app.UseMvc(routes => {
         routes.MapRoute(
             name: "",
             template: "Student/ReviewList",
             defaults: new { controller = "Review", action = "List", area = "Student" }
             );
         routes.MapRoute(
             name: "",
             template: "Student/CreateReview/{courseCode}",
             defaults: new { controller = "Review", action = "Create", area = "Student" }
             );
         routes.MapRoute(
             name: "",
             template: "Student/UnEnroll/{courseCode}",
             defaults: new { controller = "Student", action = "UnEnroll", area = "Student" }
             );
         routes.MapRoute(
             name: "",
             template: "Student/Enroll/{courseCode}",
             defaults: new { controller = "Student", action = "Enroll", area = "Student" }
             );
         routes.MapRoute(
             name: "",
             template: "Faculty/Manage/{courseCode}",
             defaults: new { controller = "Course", action = "Manage", area = "Faculty" }
             );
         routes.MapRoute(
             name: "",
             template: "Faculty/Edit/{courseCode}",
             defaults: new { controller = "Course", action = "Edit", area = "Faculty" }
             );
         routes.MapRoute(
             name: "",
             template: "Student/{action=Index}",
             defaults: new { controller = "Student", area = "Student" }
             );
         routes.MapRoute(
             name: "",
             template: "Account/{action=Index}",
             defaults: new { controller = "Account", area = "Admin" }
             );
         routes.MapRoute(
             name: "",
             template: "Admin/{action=Index}",
             defaults: new { controller = "Account", area = "Admin" }
             );
         routes.MapRoute(
             name: "",
             template: "Faculty/{action=Index}",
             defaults: new { controller = "Course", area = "Faculty" }
             );
         routes.MapRoute(
             name: "Register",
             template: "Register",
             defaults: new { area = "Admin", controller = "Account", action = "Create" }
             );
         routes.MapRoute(
             name: "Login",
             template: "Login",
             defaults: new { area = "Admin", controller = "Account", action = "Login" }
             );
         routes.MapRoute(
             name: "Logout",
             template: "Logout",
             defaults: new { area = "Admin", controller = "Account", action = "Logout" }
             );
         routes.MapRoute(
             name: "AccessDenied",
             template: "AccessDenied",
             defaults: new { area = "Admin", controller = "Account", action = "AccessDenied" }
             );
         routes.MapRoute(
             name: "default",
             template: "{controller=Guest}/{action=Index}",
             defaults: new { area = "Guest" }
             );
     });
     SeedData.Populate(app);
     IdentitySeedData.Populate(app);
 }
コード例 #8
0
ファイル: Startup.cs プロジェクト: Chevakin/SportsStore
        // 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.UseStatusCodePages();
            }
            else
            {
                app.UseExceptionHandler("/Error");
            }

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

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: null,
                    pattern: "{area:exists}/{controller=Admin}/{action=Index}");

                endpoints.MapControllerRoute(
                    name: null,
                    pattern: "{category}/Page{productPage:int}",
                    defaults: new { controller = "Product", action = "List" });

                endpoints.MapControllerRoute(
                    name: null,
                    pattern: "Page{productPage:int}",
                    defaults: new { controller  = "Product", action = "List",
                                    productPage = 1 });

                endpoints.MapControllerRoute(
                    name: null,
                    pattern: "{category}",
                    defaults: new { controller  = "Product", action = "List",
                                    productPage = 1 });

                endpoints.MapControllerRoute(
                    name: null,
                    pattern: "",
                    defaults: new { controller  = "Product", action = "List",
                                    productPage = 1 });

                endpoints.MapControllerRoute(
                    name: null,
                    pattern: "{controller}/{action}/{id?}"
                    );

                //endpoints.MapGet("/", async context =>
                //{
                //    await context.Response.WriteAsync("Hello World!");
                //});
            });

            SeedData.EnsurePopulated(app);
            IdentitySeedData.EnsurePopulated(app);
        }
コード例 #9
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseDeveloperExceptionPage();
            app.UseStatusCodePages();
            app.UseStaticFiles();


            app.UseRouting();

            app.UseAuthentication();
            //app.UseAuthorization();
            app.UseAuthorization();
            //app.UseMvcWithDefaultRoute();


            app.UseEndpoints(endpoints =>
            {
                //endpoints.MapControllers();
                //endpoints.MapControllerRoute(
                //    name: "pagination",
                //    pattern: "Cars/Page{carPage}",
                //    defaults: new { Controller = "Car", action = "Index" });

                //endpoints.MapControllerRoute(
                //    name: "default",
                //    pattern: "{controller=Car}/{action=List}/{id?}");// .MapControllers();

                endpoints.MapControllerRoute("default",
                                             "/{controller=Car}/{action=Index}/{id?}");
                //endpoints.MapControllerRoute("controllers",
                //    "controllers/{controller=Home}/{action=Index}/{id?}");
                //endpoints.MapDefaultControllerRoute();
                endpoints.MapRazorPages();
                endpoints.MapBlazorHub();
                endpoints.MapFallbackToPage("/_Host");
                //endpoints.MapFallbackToController("Blazor", "Home");
            });

            IdentitySeedData.CreateAdminAccount(app.ApplicationServices, Configuration);

            //app.UseAuthentication();


            //IdentitySeedData.EnsurePopulated(app);

            //app.UseMvcWithDefaultRoute();
            //app.UseMvc(routes => {
            //    routes.MapRoute(
            //        name: "pagination",
            //        template: "Cars/Page{carPage}",
            //        defaults: new { Controller = "Car", action = "Index" });

            //    routes.MapRoute(
            //        name: "default",
            //        template: "{controller=Car}/{action=Index}/{id?}");
            //});
            //app.UseMvc(routes =>
            //{
            //    routes.MapRoute(
            //        name: "default",
            //        template: "{controller}/{action}",
            //        defaults: new { controller = "Car", action = "Index" });
            //});
            //if (env.IsDevelopment())
            //{
            //    app.UseDeveloperExceptionPage();
            //}

            //app.UseRouting();

            //app.UseEndpoints(endpoints =>
            //{
            //    endpoints.MapGet("/", async context =>
            //    {
            //        await context.Response.WriteAsync("Hello World! From Kernel Cars");
            //    });
            //});
        }
コード例 #10
0
 public AccountController(UserManager <AppUser> userMgr, SignInManager <AppUser> signinMgr, RoleManager <IdentityRole> roleMgr)
 {
     userManager   = userMgr;
     signInManager = signinMgr;
     IdentitySeedData.CreateSuperAdminAccount(userMgr, roleMgr).Wait();
 }
コード例 #11
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.IsProduction())
            {
                app.UseExceptionHandler("/error");
            }
            else
            {
                app.UseDeveloperExceptionPage();
                app.UseStatusCodePages();
            }

            /* добавление стандартных MiddleWare-звеньев
             * в PipeLine приложения */
            app.UseStaticFiles();
            app.UseSession();
            app.UseRouting();

            // Identity
            // Вход / Выход
            app.UseAuthentication();
            // Допуск / Недопуск к ресурсам
            app.UseAuthorization();

            app.UseEndpoints(endpoints => {
                /* endpoints.MapControllerRoute("pagination",
                 *  "Products/{Page?}/{productPage:regex(^[1-9]\\d*$)=1}",
                 *  new { Controller = "Home", action = "Index" }); */

                endpoints.MapControllerRoute("catpage",
                                             "{category}/Page{productPage::regex(^[1-9]\\d*$)=1}",
                                             new { Controller = "Home", action = "Index" });
                endpoints.MapControllerRoute("page", "Page{productPage::regex(^[1-9]\\d*$)=1}",
                                             new {
                    Controller = "Home", action = "Index"
                });
                endpoints.MapControllerRoute("category", "{category}",
                                             new {
                    Controller = "Home", action = "Index", productPage =
                        1
                });
                endpoints.MapControllerRoute("pagination",
                                             "Products/Page{productPage:regex(^[1-9]\\d*$)=1}",
                                             new {
                    Controller = "Home", action = "Index"
                });
                // добавление роута по умолчанию
                endpoints.MapDefaultControllerRoute();
                // добавление роута серверных страниц
                endpoints.MapRazorPages();
                endpoints.MapBlazorHub();
                endpoints.MapFallbackToPage("/admin/{*catchall}", "/Admin/Index");
                // The same:

                /* endpoints.MapControllerRoute("pagination",
                 *  "Products/{Page?}/{productPage:regex(^[1-9]\\d*$)}",
                 *  new { Controller = "Home", action = "Index", productPage = 1 });
                 *  endpoints.MapDefaultControllerRoute();
                 * }); */
                // endpoints.MapDefaultControllerRoute ();
            });
            // Заполнение БД демонстрационными данными
            SeedData.EnsurePopulated(app);
            // Заполнение БД демонстрационными данными системы безопасности Identity
            IdentitySeedData.EnsurePopulated(app);
        }
コード例 #12
0
ファイル: Startup.cs プロジェクト: ivobrands/fletniks
        // 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, IdentitySeedData seeder)
        {
            InitializeDbTestData(app);

            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

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

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationScheme  = "idsrv",
                AutomaticAuthenticate = false,
                AutomaticChallenge    = false
            });

            app.UseIdentity();

            app.UseIdentityServer();

            app.UseStaticFiles();

            app.UseMvcWithDefaultRoute();

            seeder.EnsureSeedData().Wait();
        }
コード例 #13
0
ファイル: Startup.cs プロジェクト: daredammy/StyledByAdeola
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IAntiforgery antiforgery,
                              UserManager <AppUser> userManager, RoleManager <IdentityRole> RoleManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseStatusCodePages();
            }
            else
            {
                app.UseExceptionHandler("/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();
            if (!env.IsDevelopment())
            {
                app.UseSpaStaticFiles();
            }

            // allows the session system to automatically associate requests with sessions when they arrive from client
            app.UseSession();
            if (env.IsDevelopment())
            {
                app.UseSwagger();
                app.UseSwaggerUI(options =>
                {
                    options.SwaggerEndpoint("/swagger/v1/swagger.json",
                                            "StyledByAdeola API");
                });
            }
            app.UseRouting();
            app.UseAuthentication();

            app.UseAuthorization();

            app.Use(nextDelegate => context => {
                string path         = context.Request.Path.Value;
                string[] directUrls = { "/admin", "/store", "/cart", "/braintree", "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}/{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

                string strategy = Configuration
                                  .GetValue <string>("DevTools:ConnectionStrategy");

                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    if (strategy == "proxy")
                    {
                        spa.UseProxyToSpaDevelopmentServer("http://127.0.0.1:4200");
                    }
                    else if (strategy == "managed")
                    {
                        spa.UseAngularCliServer(npmScript: "start");
                    }
                }
            });

            if ((Configuration["INITDB"] ?? "false") == "true")
            {
                string email         = Configuration.GetValue <string>("Email");
                string adminPassword = Configuration.GetValue <string>("AdminPassword");
                System.Console.WriteLine("Preparing Database...");
                IdentitySeedData.EnsurePopulated(userManager, RoleManager, email, adminPassword).GetAwaiter().GetResult();
                System.Console.WriteLine("Database Preparation Complete");
            }
        }
コード例 #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)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();
            app.UseCookiePolicy();
            app.UseSession();
            app.UseAuthentication();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
                routes.MapRoute(
                    name: null,
                    template: "{category}/Page{productPage:int}",
                    defaults: new { controller = "Product", action = "List" }
                    );

                routes.MapRoute(
                    name: null,
                    template: "Page{productPage:int}",
                    defaults: new { controller = "Product", action = "List", productPage = 1 }
                    );

                routes.MapRoute(
                    name: null,
                    template: "{category}",
                    defaults: new { controller = "Product", action = "List", productPage = 1 }
                    );
                routes.MapRoute(
                    name: "Orders",
                    template: "{controller=Order}/{action=List}/{id?}");
                routes.MapRoute(
                    name: "Rentals",
                    template: "{controller=Rental}/{action=List}/{id?}");
                routes.MapRoute(
                    name: "Admin-Index",
                    template: "{controller=Admin}/{action=Index}/{id?}");
                routes.MapRoute(
                    name: "Admin-Edit",
                    template: "{controller=Admin}/{action=Edit}/{id?}");
                routes.MapRoute(
                    name: "ActionLogs",
                    template: "{controller=Home}/{action=ActionLogs}"
                    );
                routes.MapRoute(
                    name: null,
                    template: "Account/{action}/{ReturnUrl}",
                    defaults: new { controller = "Accoubt" }
                    );
            });
            SeedData.EnsurePopulated(app);
            IdentitySeedData.EnsurePopulated(app);
        }
コード例 #15
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.UseDeveloperExceptionPage();
            app.UseStatusCodePages();
            app.UseStaticFiles();
            app.UseSession();
            app.UseAuthentication();
            app.UseMvc(routes => {
                routes.MapRoute(
                    name: null,
                    template: "/Admin/Orders/sort-{sortOrder}/Page{productPage:int}",
                    defaults: new { controller = "Order", action = "List" });

                routes.MapRoute(
                    name: null,
                    template: "/Admin/Orders/Page{productPage:int}",
                    defaults: new { controller = "Order", action = "List" });

                routes.MapRoute(
                    name: null,
                    template: "/Admin/Orders",
                    defaults: new { controller = "Order", action = "List" });

                routes.MapRoute(
                    name: null,
                    template: "Admin/sort-{sortOrder}/Page{productPage:int}",
                    defaults: new { controller = "Admin", action = "Index" });

                routes.MapRoute(
                    name: null,
                    template: "Admin/Page{productPage:int}",
                    defaults: new { controller = "Admin", action = "Index" });

                routes.MapRoute(
                    name: null,
                    template: "Admin/sort-{sortOrder}",
                    defaults: new { controller = "Admin", action = "Index" });

                routes.MapRoute(
                    name: null,
                    template: "Admin",
                    defaults: new { controller = "Admin", action = "Index" });

                routes.MapRoute(
                    name: null,
                    template: "genre-{genre}/Page{productPage:int}",
                    defaults: new { controller = "Product", action = "List" });

                routes.MapRoute(
                    name: null,
                    template: "Page{productPage:int}",
                    defaults: new { controller = "Product", action = "List", productPage = 1 });

                routes.MapRoute(
                    name: null,
                    template: "genre-{genre}",
                    defaults: new { controller = "Product", action = "List", productPage = 1 });

                routes.MapRoute(
                    name: null,
                    template: "",
                    defaults: new { controller = "Product", action = "List", productPage = 1 });

                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action}/{id?}");
            });

            SeedData.EnsurePopulated(app);
            IdentitySeedData.EnsurePopulated(app);
        }
コード例 #16
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, IdentitySeedData identitySeedData)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            //var options = new RewriteOptions()
            //   .AddRedirectToHttps();

            //app.UseRewriter(options);

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

            app.UseStaticFiles();

            app.UseSession();

            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "category",
                    template: "Products/Category/{category}/{productPage}",
                    defaults: new { Controller = "Products", Action = "Index" }
                    );
                routes.MapRoute(
                    name: "pagination",
                    template: "Products/{productPage}",
                    defaults: new { Controller = "Products", Action = "Index" }
                    );
                //routes.MapRoute(
                //   name: "sorting",
                //   template: "Products/{productPage}",
                //   defaults: new { Controller = "Products", Action = "Index" }
                //   );
                routes.MapRoute(
                    name: "cart",
                    template: "Cart",
                    defaults: new { Controller = "Cart", Action = "Index" }
                    );

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

            identitySeedData.EnsurePopulated().Wait();
        }
コード例 #17
0
 public AccountController(UserManager <IdentityUser> userManager, SignInManager <IdentityUser> signInManager)
 {
     _userManager   = userManager;
     _signInManager = signInManager;
     IdentitySeedData.EnsurePopulated(userManager).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)
        {
            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.UseForwardedHeaders(new ForwardedHeadersOptions
            {
                ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
            });


            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseRouting();
            app.UseAuthorization();
            app.UseSession();
            app.UseAuthentication();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: null,
                    pattern: "{category}/Page{page:int}",
                    defaults: new { controller = "Product", action = "List" }
                    );

                endpoints.MapControllerRoute(
                    name: null,
                    pattern: "Page{productPage:int}",
                    defaults: new
                {
                    controller  = "Product",
                    action      = "List",
                    productPage = 1
                });
                endpoints.MapControllerRoute(
                    name: null,
                    pattern: "{category}",
                    defaults: new
                {
                    controller  = "Product",
                    action      = "List",
                    productPage = 1
                });
                endpoints.MapControllerRoute(
                    name: null,
                    pattern: "",
                    defaults: new
                {
                    controller  = "Product",
                    action      = "List",
                    productPage = 1
                });
                endpoints.MapControllerRoute(name: null, pattern: "{controller}/{action}/{id?}");
            });
            SeedData.EnsurePopulated(app);
            IdentitySeedData.EnsurePopulated(app);
        }