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); }
// 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(); //iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii 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); //iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii IdentitySeedData.EnsurePopulated(app); }
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); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseDeveloperExceptionPage(); app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions { HotModuleReplacement = true }); //if (env.IsDevelopment()) { // app.UseDeveloperExceptionPage(); // app.UseBrowserLink(); //} else { // app.UseExceptionHandler("/Home/Error"); //} app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); routes.MapSpaFallbackRoute("angular-fallback", new { controller = "Home", action = "Index" }); }); SeedData.SeedDatabase(app); }
public static void Main(string[] args) { var host = BuildWebHost(args); //it was necessary to diverge from the book here and use //this tutorial to get seeding to work: https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app-xplat/adding-model using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { // Requires using SportsStore.Models; SeedData.Initialize(services); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred seeding the DB."); } } host.Run(); }
// 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.UseRouting(); app.UseStatusCodePages(); app.UseStaticFiles(); 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?}"); }); SeedData.EnsurePopulated(app); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, DataContext context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseSpaStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); app.UseSpa(spa => { spa.Options.SourcePath = "ClientApp"; if (env.IsDevelopment()) { spa.UseAngularCliServer(npmScript: "start"); //spa.UseProxyToSpaDevelopmentServer("http://localhost:4200"); } }); SeedData.SeedDatabase(context); }
/// <summary> /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. /// </summary> /// <param name="app"> /// The ApplicationBuilder. /// </param> /// <param name="env"> /// The WebHostEnvironment. /// </param> public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } // Ётот расшир¤ющий метод включает по,одержку дл¤ обслуживани¤ статического содержимого из папки wwwroot app.UseStaticFiles(); /* * Ётот расшир¤ющий метод добавл¤ет простое сообщение * в Ќ““–-ответы, которые иначе не имели бы тела, такие * как ответы 404 - Not Found(404 - не найдено) */ app.UseStatusCodePages(); app.UseRouting(); app.UseAuthorization(); // app.UseEndpoints( // endpoints => // { // endpoints.MapControllers(); // endpoints.MapControllerRoute( // name: "pagination", // pattern: "Products/Page{productPage}"); // endpoints.MapControllerRoute( // name: "default", // pattern: "{controller=Home}/{action=Index}/{id?}"); // }); app.UseSession(); app.UseMvc( routes => { routes.MapRoute( name: null, "{category}/Page{productPage:int}", defaults: new { controller = "Product", action = "List" }); routes.MapRoute( null, "Page{productPage:int}", defaults: new { controller = "Product", action = "List", productPage = 1 }); routes.MapRoute( null, "{category}", defaults: new { controller = "Product", action = "List", productPage = 1 }); routes.MapRoute( null, "", defaults: new { controller = "Product", action = "List", productPage = 1 }); routes.MapRoute(name: null, template: "{controller}/{action}/{id?}"); }); SeedData.EnsurePopulated(app); }
// 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(); } else { app.UseExceptionHandler("/Error"); } app.UseStaticFiles(); app.UseSession(); app.UseAuthentication(); app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions() { ConfigFile = "webpack.config.js", //this is defualt value HotModuleReplacement = true, ReactHotModuleReplacement = true, //for React only }); 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); //IdentitySeedData.EnsurePopulated(app).Wait(); }
/// <summary> /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. /// </summary> /// <param name="app"> /// The ApplicationBuilder. /// </param> /// <param name="env"> /// The WebHostEnvironment. /// </param> public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } // Ётот расшир¤ющий метод включает по,одержку дл¤ обслуживани¤ статического содержимого из папки wwwroot app.UseStaticFiles(); /* * Ётот расшир¤ющий метод добавл¤ет простое сообщение * в Ќ““–-ответы, которые иначе не имели бы тела, такие * как ответы 404 - Not Found(404 - не найдено) */ app.UseStatusCodePages(); app.UseRouting(); app.UseAuthorization(); //var supportedCultures = new[] // { // new CultureInfo("en-US"), // new CultureInfo("ru-ru"), // }; //app.UseRequestLocalization(new RequestLocalizationOptions // { // DefaultRequestCulture = new RequestCulture("ru-RU"), // // Formatting numbers, dates, etc. // SupportedCultures = supportedCultures, // // UI strings that we have localized. // SupportedUICultures = supportedCultures // }); app.UseRequestLocalization(); CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US"); CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-US"); // app.UseEndpoints( // endpoints => // { // endpoints.MapControllers(); // endpoints.MapControllerRoute( // name: "pagination", // pattern: "Products/Page{productPage}"); // endpoints.MapControllerRoute( // name: "default", // pattern: "{controller=Home}/{action=Index}/{id?}"); // }); app.UseSession(); app.UseMvc( routes => { routes.MapRoute( name: null, "{category}/Page{productPage:int}", defaults: new { controller = "Product", action = "List" }); routes.MapRoute( null, "Page{productPage:int}", defaults: new { controller = "Product", action = "List", productPage = 1 }); routes.MapRoute( null, "{category}", defaults: new { controller = "Product", action = "List", productPage = 1 }); routes.MapRoute( null, "", defaults: new { controller = "Product", action = "List", productPage = 1 }); routes.MapRoute(name: null, template: "{controller}/{action}/{id?}"); }); SeedData.EnsurePopulated(app); }
// 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); }
// This method gets called by the runtime. Use this method to set up features that receive and process //Http requests public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseDeveloperExceptionPage(); //only available in development process, not available in deployed applications app.UseStatusCodePages(); //add simple messages to Http responses app.UseStaticFiles(); //method enables support for serving static content from the wwwroot folder. app.UseSession(); app.UseMvc(routes => { //add new route before default //routes.MapRoute( // name: "pagination", // template: "Products/Page{productPage}", // defaults: new { Controller = "Product", action = "List" }); //routes.MapRoute( // name: "default", // template: "{controller=Product}/{action=List}/{id?}"); //I need to tell MVC that it should send requests that arrive for the root URL of my application (http:// //mysite /) to the List action method in the ProductController class 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); //seed the database when the application starts }