コード例 #1
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.UseRouting();

            app.UseAuthorization();

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

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

            app.UseSession();

            app.UseRouting();

            app.UseAuthorization();

            //Change the url endpoints to be what we want
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    "catpage",
                    "{category}/{pageNum:int}",
                    new { Controller = "Home", action = "Index" });

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

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

                endpoints.MapControllerRoute(
                    "pagination",
                    "Books/{pageNum}",
                    new { Controller = "Home", action = "Index" });

                endpoints.MapDefaultControllerRoute();

                endpoints.MapRazorPages();
            });

            //Run this function and pull in app from SeedData
            SeedData.EnsurePopulated(app);
        }
コード例 #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)
        {
            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 =>
            {
                //Custom url for when user inputs category and page number
                endpoints.MapControllerRoute(
                    "catandpage",
                    "{category}/{page:int}",
                    new { Controller = "Home", action = "Index" });

                //Custom url for when user inputs number only
                endpoints.MapControllerRoute(
                    "pageonly",
                    "{page:int}",
                    new { Controller = "Home", action = "Index" });

                //Custom url for when user inputs category only
                endpoints.MapControllerRoute(
                    "catonly",
                    "{category}",
                    new { Controller = "Home", action = "Index", page = 1 }); //Set default page as 1

                //Customize the url user sees when navigating to different page numbers of the Index view
                endpoints.MapControllerRoute(
                    "pagination",
                    "P{page:int}",
                    new { Controller = "Home", action = "Index" });

                endpoints.MapDefaultControllerRoute();
            });

            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)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseSession();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                //if the user passes category and page number Ex. Classic/1
                endpoints.MapControllerRoute("catpage",
                                             "{category}/{pageNum:int}",
                                             new { Controller = "Home", action = "Index" });

                //if the user passes category and page number with "P" Ex. Classic/P1
                endpoints.MapControllerRoute("catpage",
                                             "{category}/P{pageNum:int}",
                                             new { Controller = "Home", action = "Index" });

                //if the user passes Books/page number Ex.Books/2
                endpoints.MapControllerRoute("page",
                                             "Books/{pageNum:int}",
                                             new { Controller = "Home", action = "Index" });

                //if the user passes only the page number Ex./2
                endpoints.MapControllerRoute("page",
                                             "{pageNum:int}",
                                             new { Controller = "Home", action = "Index" });

                //if the user  passes /Books and category Ex. Books/Classic
                endpoints.MapControllerRoute("category",
                                             "Books/{category}",
                                             new { Controller = "Home", action = "Index", page = 1 });

                //if the user only passes category Ex. /Classic
                endpoints.MapControllerRoute("category",
                                             "{category}",
                                             new { Controller = "Home", action = "Index", page = 1 });

                //if the user passes Ex./P2
                //This used to work,but doesn't work now
                //If I delete the new endpoints /p2 will direct me to the right page
                endpoints.MapControllerRoute(
                    "pagination",
                    "P{pageNum}",
                    new { Controller = "Home", action = "Index" });

                endpoints.MapDefaultControllerRoute();

                endpoints.MapRazorPages();
            });

            SeedData.EnsurePopulated(app); //bring the seed data
        }