コード例 #1
0
ファイル: Startup.cs プロジェクト: aford9880/Discounts
        // 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.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints => {
                /*endpoints.MapControllerRoute(
                 *  name: null,
                 *  //url: "Page{page}",
                 *  defaults: new {
                 *      controller = "Game", action = "List"
                 *  });*/

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

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

            using (var scope = app.ApplicationServices.CreateScope()) { // создаем область (окружение) для использования сервиса AppDBContent
                AppDbContext context = scope.ServiceProvider.GetRequiredService <AppDbContext>();
                AppDbContextSeed.Initial(context);                      // Обращаемся к БД за товарами
            }
        }