コード例 #1
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.UseStatusCodePages();
            app.UseStaticFiles();
            app.UseSession();
            app.UseMvc(routes => {
                //routes.MapRoute(
                //    name: "pagination",
                //    template: "Products/Page{productPage}",
                //    defaults: new { Controller = "Product", action = "List" });

                //routes.MapRoute(
                //    name: "default",
                //    template: "{controller=Product}/{action=List}/{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: null, template: "", defaults: new { controller = "Product", action = "List", productPage = 1 });
                routes.MapRoute(name: null, template: "{controller}/{action}/{id?}");
            });

            SeedData.EnsurePopulated(app);


            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("Hello World!");
            //});
        }
コード例 #2
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();
     app.UseDeveloperExceptionPage();
     app.UseStatusCodePages();
     app.UseStaticFiles();
     app.UseSession();                                                                                     //Vigtigt at placere denne før UseMvcWithDefaultRoute()" og "UseMvc(routes =>...)" - alt, der har med routes at gøre!!
     app.UseMvcWithDefaultRoute();
     app.UseMvc(routes =>
     {
         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?}");
     });
     SeedData.EnsurePopulated(app);
 }
コード例 #3
0
ファイル: Startup.cs プロジェクト: liefuzhang/SportsStore
        // 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)
        {
            app.UseDeveloperExceptionPage();
            app.UseStatusCodePages();
            app.UseStaticFiles();
            app.UseSession();
            app.UseMvc(routes => {
                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?}");
            });
            SeedData.EnsurePopulated(app);
        }
コード例 #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)
        {
            app.UseDeveloperExceptionPage();
            app.UseStatusCodePages();
            app.UseStaticFiles();
            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                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: "Default",
                    pattern: "{controller=product}/{action=List}/{id?}");
            });

            SeedData.EnsurePopulated(app);
        }
コード例 #5
0
ファイル: Startup.cs プロジェクト: Sathiyaraman/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.IsProduction())
            {
                app.UseExceptionHandler("/error");
            }
            else
            {
                app.UseDeveloperExceptionPage();
                app.UseStatusCodePages();
            }
            app.UseStaticFiles();
            app.UseSession();

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute("catpage", "{category}/Page{ProductPage:int}", new { Controller = "Home", action = "Index" });
                endpoints.MapControllerRoute("page", "Page{ProductPage:int}", new { Controller = "Home", action = "Index", ProductPage = 1 });
                endpoints.MapControllerRoute("category", "{category}", new { Controller = "Home", action = "Index", ProductPage = 1 });
                endpoints.MapControllerRoute("pagination", "Products/Page{ProductPage}", new { Controller = "Home", action = "Index", ProductPage = 1 });
                endpoints.MapDefaultControllerRoute();
                endpoints.MapRazorPages();
                endpoints.MapBlazorHub();
                endpoints.MapFallbackToPage("/admin/{*catchall}", "/Admin/Index");
            });
            SeedData.EnsurePopulated(app);
            IdentitySeedData.EnsurePopulated(app);
        }
コード例 #6
0
        // Используется для настройки средств, которые получают и обрабатывают HTTP-запросы
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            // Отображает детали исключения, которые произошли в процессе работы
            app.UseDeveloperExceptionPage();
            // Добавляет простые сообщения в HTTP-ответы, которые иначе не имели бы тела (например, 404 - Not Found)
            app.UseStatusCodePages();
            // Включает поддержку для обслуживания статического содержимого из папки wwwroot
            app.UseStaticFiles();
            app.UseSession();
            // Включает инфраструктуру MVC
            app.UseMvc(routes =>
            {
                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: "",
                    defaults: new { Controller = "Product", Action = "List", ProductPage = 1 }
                    );
                routes.MapRoute(
                    "default",
                    "{controller=Product}/{action=List}/{id?}"
                    );
            });

            SeedData.EnsurePopulated(app);
        }
コード例 #7
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.UseSession();
            app.UseRouting();
            app.UseEndpoints(endpoints => {
                endpoints.MapControllerRoute("catpage",
                                             "{category}/Page{productPage:int}",
                                             new { Controller = "Home", action = "Index" });

                endpoints.MapControllerRoute("page", "Page{productPage:int}",
                                             new { Controller = "Home", action = "Index", productPage = 1 });

                endpoints.MapControllerRoute("category", "{category}",
                                             new { Controller = "Home", action = "Index", productPage = 1 });

                endpoints.MapControllerRoute("pagination",
                                             "Products/Page{productPage}",
                                             new { Controller = "Home", action = "Index", productPage = 1 });
                endpoints.MapDefaultControllerRoute();
                endpoints.MapRazorPages();
            });

            SeedData.EnsurePopulated(app);
        }
コード例 #8
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.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseStatusCodePages();

            app.UseRouting();

            app.UseAuthorization();

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

                endpoints.MapControllerRoute("pagination",
                                             "Product/Page(productPage)",
                                             new { Controller = "Home", action = "Index" });
            });
            SeedData.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)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseDeveloperExceptionPage();
            app.UseStatusCodePages();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute("pagination",
                                             "Pordocts/Page{productPage}",
                                             new { Controller = "Home", Action = "Index" });
                endpoints.MapDefaultControllerRoute();
                //endpoints.MapGet("/", async context =>
                //{
                //    await context.Response.WriteAsync("Hello World!");
                //});
            });
            SeedData.EnsurePopulated(app);
        }
コード例 #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)
        {
            //if (env.IsDevelopment())
            //{
            //    app.UseDeveloperExceptionPage();
            //}

            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("Hello World!");
            //});

            app.UseDeveloperExceptionPage();
            app.UseStatusCodePages();
            app.UseStaticFiles();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Product}/{action=List}/{id?}"
                    );
            });

            SeedData.EnsurePopulated(app);
        }
コード例 #11
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("/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.UseStatusCodePages();
            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseMvc(routes => {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Product}/{action=List}/{id?}"
                    );
            });
            SeedData.EnsurePopulated(app);
        }
コード例 #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, ApplicationDbContext appDbContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseStatusCodePages();
            }
            else
            {
                app.UseExceptionHandler("/Error");
            }

            app.UseStaticFiles();
            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?}");
            });

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.Run(async(context) =>
            {
                await context.Response.WriteAsync("Hello World!");
            });

            SeedData.EnsurePopulated(appDbContext);
            //IdentitySeedData.EnsurePopulated(app);
        }
コード例 #13
0
ファイル: Startup.cs プロジェクト: APU777/SportsStore
        // 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, IServiceProvider serviceProvider)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseStatusCodePages();
            }
            else
            {
                app.UseExceptionHandler("/Error");
            }

            app.UseStaticFiles();
            app.UseSession();
            app.UseAuthentication();//UseIdentity(); - obsolete
            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?}/");

                //routes.MapRoute(
                //    name: "pagination",
                //    template: "Products/Page/{page}/",
                //    defaults: new { Controller = "Product", action = "List" });

                //routes.MapRoute(
                //    name: "default",
                //    template: "{controller=Product}/{action=List}/{id?}");
            });
            SeedData.EnsurePopulated(serviceProvider);
            IdentitySeedData.EnsurePopulated(serviceProvider);
        }
コード例 #14
0
 public void Configure(IApplicationBuilder app, IHostingEnvironment env)
 {
     app.UseDeveloperExceptionPage();
     app.UseStatusCodePages();
     app.UseStaticFiles();
     //app.UseBrowserLink();
     app.UseMvcWithDefaultRoute();
     SeedData.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, 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.UseStatusCodePages();
            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseRouting();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                // Выводит определенную страницу товаров заданной категории
                // /Soccer/Page2
                endpoints.MapControllerRoute(
                    name: null,
                    pattern: "{category}/Page{productPage:int}",
                    defaults: new { Controller = "Product", Action = "List" });

                // Выводит страницу пагинации списка товаров всех категорий
                // /Page2
                endpoints.MapControllerRoute(
                    name: null,
                    pattern: "Page{productPage:int}",
                    defaults: new { Controller = "Product", Action = "List", productPage = 1 });

                // Выводит первую страницу товаров выбранной категории
                // /Soccer
                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);
        }
コード例 #16
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())
            {
                //Use simple HTML to notify the user an error has ocurred
                app.UseExceptionHandler("/error");
            }
            else
            {
                //Display exception details. Not to be used in prod
                app.UseDeveloperExceptionPage();
                // Add message for HTTP res that dont have body (i.e. 404)
                app.UseStatusCodePages();
            }
            // Enable serving static content from wwwroot
            app.UseStaticFiles();
            // Endpoint routing
            app.UseRouting();
            //Assosiate requests with sessions
            app.UseSession();
            //Enable authentication and authorization
            app.UseAuthentication();
            app.UseAuthorization();
            // Endpoint routing
            app.UseEndpoints(endpoints =>
            {
                //Add support for more apealing page paths
                // / -> First page of products for all categories
                // /Page2 -> Specified page of products for all categories
                // /Soccer -> First page of products for sprecified category
                // /Soccer/Page2 -> Specified page of products for sprecified category
                endpoints.MapControllerRoute("catpage",
                                             "{category}/Page{productPage:int}",
                                             new { Controller = "Home", action = "Index" });
                endpoints.MapControllerRoute("page",
                                             "Page{productPage:int}",
                                             new { Controller = "Home", action = "Index", productPage = 1 });
                endpoints.MapControllerRoute("category",
                                             "{category}",
                                             new { Controller = "Home", action = "Index", productPage = 1 });

                endpoints.MapControllerRoute("pagination",
                                             "Products/Page{productPage}",
                                             new { Controller = "Home", action = "Index", productPage = 1 });
                //MVC is source of endpoints
                endpoints.MapDefaultControllerRoute();
                endpoints.MapRazorPages();
                endpoints.MapBlazorHub();
                endpoints.MapFallbackToPage("/admin/{*catchall}", "/Admin/Index");
            });
            //Ensure database is populated
            SeedData.EnsurePopulated(app);
            IdentitySeedData.EnsurePopulated(app);
        }
コード例 #17
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseDeveloperExceptionPage();
            app.UseStatusCodePages();
            app.UseStaticFiles();
            app.UseRouting();
            app.UseEndpoints(endpoints => {
                endpoints.MapDefaultControllerRoute();
            });

            SeedData.EnsurePopulated(app);
        }
コード例 #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();
            }

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

            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();
                // 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);
        }
コード例 #19
0
ファイル: Startup.cs プロジェクト: dirtyblankets/SportsStore
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseDeveloperExceptionPage();
            app.UseStatusCodePages();
            app.UseStaticFiles();
            app.UseMvc(routes => {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Product}/{action=List}/{id?}");
            });

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

            if (env.IsProduction())
            {
                app.UseExceptionHandler("/error");
            }
            else
            {
                app.UseDeveloperExceptionPage();
                app.UseStatusCodePages();
            }

            // Static
            app.UseStaticFiles();

            // session memory
            app.UseSession();

            // Routing
            app.UseRouting();

            // Identity (always write between routing & endpoints!)
            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute("catpage", "{category}/Page{productPage:int}", new { Controller = "Home", action = "Index" });
                endpoints.MapControllerRoute("page", "Page{productPage:int}", new { Controller = "Home", action = "Index", productPage = 1 });
                endpoints.MapControllerRoute("category", "{category}", new { Controller = "Home", action = "Index", productPage = 1 });
                endpoints.MapControllerRoute("pagination", "Products/Page{productPage}", new { Controller = "Home", action = "Index", productPage = 1 });

                endpoints.MapDefaultControllerRoute();

                // Razor Pages
                endpoints.MapRazorPages();

                // Server side Blazor
                endpoints.MapBlazorHub();
                endpoints.MapFallbackToPage("/admin/{*catchall}", "/Admin/Index");
            });

            // Populate database with sample data & user management
            SeedData.EnsurePopulated(app);
            IdentitySeedData.EnsurePopulated(app);
        }
コード例 #21
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseDeveloperExceptionPage();
            app.UseStatusCodePages();
            app.UseStaticFiles();
            app.UseSession();
            app.UseAuthentication();
            app.UseMvc(routes =>
            {
                // /Category/Page2
                routes.MapRoute(
                    name: null,
                    template: "{category}/{productPage:int}",
                    defaults: new { controller = "Product", action = "List" }
                    );
                // /Page2
                routes.MapRoute(
                    name: null,
                    template: "Page{productPage:int}",
                    defaults: new { controller = "Product", action = "List", productPage = 1 }
                    );

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

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

                //routes.MapRoute(
                //    name: "pagination",
                //    template: "Products/Page{productPage}",
                //    defaults: new { Controller = "Product", action = "List" }
                //);

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

            SeedData.EnsurePopulated(app);         //populate db
            IdentitySeedData.EnsurePopulated(app); // populate identity db
        }
コード例 #22
0
        public void Configure(IApplicationBuilder app,
                              IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseStatusCodePages();
            }
            else
            {
                app.UseExceptionHandler("/Error");
            }
            app.UseDefaultFiles();
            app.UseStaticFiles();
            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 }
                    );

                // This route will be ignored because we have a wwwroot/index.html file and app.UseDefaultFiles() before these route definitions. So the base URL will serve up the index.html file.
                routes.MapRoute(
                    name: null,
                    template: "",
                    defaults: new { controller = "Product", action = "List", page = 1 });

                routes.MapRoute(name: null, template: "{controller}/{action}/{id?}");
            });
            SeedData.EnsurePopulated(app);
            IdentitySeedData.EnsurePopulated(app);
        }
コード例 #23
0
ファイル: Startup.cs プロジェクト: TarasBorovyk/SportsStore
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseSession();
            app.UseIdentity();
            app.UseMvcWithDefaultRoute();
            app.UseStaticFiles();
            app.UseStatusCodePages();
            app.UseDeveloperExceptionPage();
            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?}");
            });
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
            }
            SeedData.EnsurePopulated(app);
            IdentitySeedData.EnsurePopulated(app);
        }
コード例 #24
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args).Build();

            using (var scope = host.Services.CreateScope()) {
                var services = scope.ServiceProvider;
                try {
                    var _context = services.GetRequiredService <ApplicationDbContext>();
                    SeedData.EnsurePopulated(_context);
                } catch (Exception ex) {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding the database.");
                }
            }
            host.Run();
        }
コード例 #25
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)
        {
            app.UseDeveloperExceptionPage();
            app.UseStatusCodePages();
            app.UseStaticFiles();
            app.UseSession();
            app.UseMvcWithDefaultRoute();
            app.UseMvc(routes =>
            {
                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?}");
            });
            SeedData.EnsurePopulated(app);

            //loggerFactory.AddConsole();

            //if (env.IsDevelopment())
            //{
            //    app.UseDeveloperExceptionPage();
            //}

            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("Hello World!");
            //});
        }
コード例 #26
0
 public void Configure(IApplicationBuilder app,
                       IHostingEnvironment env, ILoggerFactory loggerFactory)
 {
     app.UseDeveloperExceptionPage();
     app.UseStatusCodePages();
     app.UseStaticFiles();
     app.UseMvc(routes => {
         routes.MapRoute(
             name: "pagination",
             template: "Products/Page{page}",
             defaults: new { Controller = "Product", action = "List" });
         routes.MapRoute(
             name: "default",
             template: "{controller=Product}/{action=List}/{id?}");
     });
     SeedData.EnsurePopulated(app);
 }
コード例 #27
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");
                // 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.UseCookiePolicy();
            app.UseStatusCodePages();
            app.UseMvc(routes =>
            {
                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: null,
                    template: "",
                    defaults: new { controller  = "Product", action = "List",
                                    productPage = 1 });
                routes.MapRoute(name: null, template: "{controller}/{action}/{id?}");
            });
            SeedData.EnsurePopulated(app);
        }
コード例 #28
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsProduction())
            {
                app.UseExceptionHandler("/error");
            }
            else
            {
                app.UseDeveloperExceptionPage();
                app.UseStatusCodePages();
            }
            // enregistrer les composants du middleware afin de traiter les requetes HTTP.
            app.UseDeveloperExceptionPage();
            app.UseStatusCodePages();
            app.UseStaticFiles();
            app.UseSession();
            app.UseRouting();
            app.UseAuthentication();
            app.UseAuthorization();
            app.UseEndpoints(endpoints => {
                endpoints.MapControllerRoute("catpage",
                                             "{category}/Page{productPage:int}",             // correspond aux href; tout les URLS qui matches avec le pattern seront traités ici
                                             new { Controller = "Home", action = "Index" }); // défini un controller pour le endpoint, ici le controler c'est HOME ainsi que la méthode d'action

                endpoints.MapControllerRoute("page",
                                             "Page{productPage:int}",
                                             new { Controller = "Home", action = "Index", productPage = 1 });

                endpoints.MapControllerRoute("category",
                                             "{category}", // les bracket veulent dire que c'est variable
                                             new { Controller = "Home", action = "Index", productPage = 1 });

                endpoints.MapControllerRoute("pagination",
                                             "Products/Page{productPage}",
                                             new { Controller = "Home", action = "Index", productPage = 1 });

                endpoints.MapDefaultControllerRoute();
                endpoints.MapRazorPages();
                endpoints.MapBlazorHub();
                endpoints.MapFallbackToPage("/admin/{*catchall}", "/Admin/Index");
            });

            SeedData.EnsurePopulated(app);
            IdentitySeedData.EnsurePopulated(app);
        }
コード例 #29
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.UseStatusCodePages();
            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                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?}");
                //routes.MapRoute(
                //    name: "pagination",
                //    template: "Products/Page{page}",
                //    defaults: new { Controller = "Product", action = "List" });

                //routes.MapRoute(
                //name: "default",
                //template: "{controller=Product}/{action=List}/{id?}");
            });
            SeedData.EnsurePopulated(app);
        }
コード例 #30
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseStatusCodePages();
            app.UseStaticFiles();
            app.UseSession();
            app.UseRouting();

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

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute("catpage",
                                             "Products/Page{productPage:int}",
                                             new { Controller = "Home", action = "Index" });

                endpoints.MapControllerRoute("page",
                                             "Page{productPage:int}",
                                             new { Controller = "Home", action = "Index", productPage = 1 });

                endpoints.MapControllerRoute("category",
                                             "{category}",
                                             new { Controller = "Home", action = "Index", productPage = 1 });

                endpoints.MapControllerRoute("pagination",
                                             "Products/Page{productPage}",
                                             new { Controller = "Home", action = "Index", productPage = 1 });
                endpoints.MapDefaultControllerRoute();
                endpoints.MapRazorPages();
                endpoints.MapBlazorHub();
                endpoints.MapFallbackToPage("/admin/{*catchall}", "/Admin/Index");
            });
            SeedData.EnsurePopulated(app);
            // to migrate Identity: dotnet ef migrations add Initial --context AppIdentityDbContext
            // to update Identity: dotnet ef database update --context AppIdentityDbContext
            // to reset Database dotnet ef database drop--force--context AppIdentityDbContext
            IdentitySeedData.EnsurePopulated(app);
        }