Esempio n. 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.UseSmidge(bundle =>
            {
                bundle.CreateJs("my-js-bundle", "~/js/").WithEnvironmentOptions(BundleEnvironmentOptions.Create().ForDebug(builder => builder.EnableCompositeProcessing().EnableFileWatcher().SetCacheBusterType <AppDomainLifetimeCacheBuster>().CacheControlOptions(enableEtag: false, cacheControlMaxAge: 0)).Build());
                bundle.CreateCss("my-css-bundle", "~/lib/bootstrap/dist/css/bootstrap.min.css", "~/css/site.css").WithEnvironmentOptions(BundleEnvironmentOptions.Create().ForDebug(builder => builder.EnableCompositeProcessing().EnableFileWatcher().SetCacheBusterType <AppDomainLifetimeCacheBuster>().CacheControlOptions(enableEtag: false, cacheControlMaxAge: 0)).Build());
            });
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });
        }
        private BundleEnvironmentOptions ConfigureBundleEnvironmentOptions(BundlingOptions bundleOptions)
        {
            var bundleEnvironmentOptions = new BundleEnvironmentOptions();

            // auto-invalidate bundle if files change in debug
            bundleEnvironmentOptions.DebugOptions.FileWatchOptions.Enabled = true;
            // set cache busters
            bundleEnvironmentOptions.DebugOptions.SetCacheBusterType(_cacheBusterType);
            bundleEnvironmentOptions.ProductionOptions.SetCacheBusterType(_cacheBusterType);
            // config if the files should be combined
            bundleEnvironmentOptions.ProductionOptions.ProcessAsCompositeFile = bundleOptions.EnabledCompositeFiles;

            return(bundleEnvironmentOptions);
        }
Esempio n. 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) //middleware eklenen yer.
        {
            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();

            //smidge kütüphanesi middleware yapýsý.

            app.UseSmidge(bundle =>
            {
                // EnableCompositeProcessing diyerek debug'da dahi olsa birleþtirme iþlemini gerçekleþtir. EnableFileWatcher oluþturdugum bundle'da dosyalarý izle, bir deðiþiklik olursa yeniden oluþtur. SetCacheBusterType<AppDomainLifetimeCacheBuster> ile uygulama ayaða kalkýnca cache'i boz ve yeniden oluþtur.
                // browser'a oluþturulan bundle dosyasýný hiç cache'leme demek için de CacheControlOptions giriyoruz. enableEtag: false yapýyoruz. enable tag bir nevi token ve bu token'a göre browser deðiþiklikleri algýlýyor. ayný tag gönderirse header, o zaman browser deðiþiklik yapmýyor ve cache bellekten ekmeðini yiyor. 304 durum kodu bi þey deðiþmemiþ cache den oku demek.
                // biz false yaptýk bu sayede browser cache çalýþmýyor ve serverdan bilgileri çekiyor. cacheControlMaxAge: 0 ise browser cache'yi ne kadar tutabilirin saniye cinsinden deðeri.
                bundle.CreateJs("my-js-bundle", "~/js/").WithEnvironmentOptions(BundleEnvironmentOptions.Create().ForDebug(builder => builder.EnableCompositeProcessing().EnableFileWatcher().SetCacheBusterType <AppDomainLifetimeCacheBuster>().CacheControlOptions(enableEtag: false, cacheControlMaxAge: 0)).Build());

                bundle.CreateCss("my-css-bundle", "~/css/site.css", "~/lib/bootstrap/dist/css/bootstrap.css");
            });

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Esempio n. 4
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddDebug(LogLevel.Debug);

            // Add the following to the request pipeline only in development environment.
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // Add Error handling middleware which catches all application specific errors and
                // sends the request to the following path or controller action.
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute("Default", "{controller=Home}/{action=Index}/{id?}");
            });

            app.UseSmidge(bundles =>
            {
                //Create pre-defined bundles

                bundles.Create("test-bundle-1",
                               new JavaScriptFile("~/Js/Bundle1/a1.js"),
                               new JavaScriptFile("~/Js/Bundle1/a2.js"),
                               //NOTE: This is already min'd based on it's file name, therefore
                               // by convention JsMin should be removed
                               new JavaScriptFile("~/Js/Bundle1/a3.min.js"))
                .WithEnvironmentOptions(bundles.DefaultBundleOptions)
                .OnOrdering(collection =>
                {
                    //return some custom ordering
                    return(collection.OrderBy(x => x.FilePath));
                });

                bundles.CreateJs("test-bundle-2", "~/Js/Bundle2")
                .WithEnvironmentOptions(BundleEnvironmentOptions.Create()
                                        .ForDebug(builder => builder
                                                  .EnableCompositeProcessing()
                                                  .EnableFileWatcher()
                                                  .SetCacheBusterType <AppDomainLifetimeCacheBuster>()
                                                  .CacheControlOptions(enableEtag: false, cacheControlMaxAge: 0))
                                        .Build()
                                        );

                bundles.Create("test-bundle-3", WebFileType.Js, "~/Js/Bundle2");

                bundles.Create("test-bundle-4",
                               new CssFile("~/Css/Bundle1/a1.css"),
                               new CssFile("~/Css/Bundle1/a2.css"));

                bundles.CreateJs("libs-js",
                                 //Here we can change the default pipeline to use Nuglify for this single bundle
                                 bundles.PipelineFactory.Create <NuglifyJs>(),
                                 "~/Js/Libs/jquery-1.12.2.js", "~/Js/Libs/knockout-es5.js");

                bundles.CreateCss("libs-css",
                                  //Here we can change the default pipeline to use Nuglify for this single bundle (we'll replace the default)
                                  bundles.PipelineFactory.DefaultCss().Replace <CssMinifier, NuglifyCss>(bundles.PipelineFactory),
                                  "~/Css/Libs/font-awesome.css");
            });

            app.UseSmidgeNuglify();
        }
Esempio n. 5
0
 /// <summary>
 /// Sets the options for the bundle
 /// </summary>
 /// <param name="bundleOptions"></param>
 public Bundle WithEnvironmentOptions(BundleEnvironmentOptions bundleOptions)
 {
     BundleOptions = bundleOptions;
     return(this);
 }
Esempio n. 6
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="files"></param>
 /// <param name="bundleOptions"></param>
 public Bundle(List <IWebFile> files, BundleEnvironmentOptions bundleOptions)
 {
     Files         = files;
     BundleOptions = bundleOptions;
 }
Esempio n. 7
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider serviceProvider)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error/500");
            }

            app.UseStatusCodePagesWithReExecute("/Error/{0}");


            app.UseStaticFiles(new StaticFileOptions()
            {
                OnPrepareResponse =
                    r =>
                {
                    string path = r.File.PhysicalPath;
                    if (
                        path.EndsWith(".gif") || path.EndsWith(".jpg") ||
                        path.EndsWith(".png") || path.EndsWith(".svg") ||
                        path.EndsWith(".webp") || path.EndsWith(".woff2") ||
                        path.EndsWith(".css") || path.EndsWith(".js") ||
                        path.EndsWith(".xml"))
                    {
                        TimeSpan maxAge = new TimeSpan(365, 0, 0, 0);
                        r.Context.Response.Headers.Append("Cache-Control", "max-age=" + maxAge.TotalSeconds.ToString("0"));
                    }
                }
            });


            app.UseStaticFiles();

            app.UseRouting();

            app.UseSession();

            app.UseCookiePolicy();

            app.UseResponseCaching();

            app.UseResponseCompression();

            app.UseCors(MyAllowSpecificOrigins);

            app.UseAuthorization();

            //var routeTable = serviceProvider.GetService<IRouteTable>();



            BundleEnvironmentOptions bundleEnvironmentOptions = BundleEnvironmentOptions.Create().ForDebug(opts =>
                                                                                                           opts.EnableCompositeProcessing()
                                                                                                           .EnableFileWatcher()
                                                                                                           .SetCacheBusterType <AppDomainLifetimeCacheBuster>()
                                                                                                           .CacheControlOptions(enableEtag: false, cacheControlMaxAge: 0)
                                                                                                           ).Build();

            app.UseSmidge(manager =>
            {
                #region Login Layout
                //toastr.min.js cdn den geliyor onu halletmeye calis
                manager.CreateJs("layout-login-js",
                                 "~/Admin/assets/libs/jquery/dist/jquery.min.js",
                                 "~/Admin/assets/libs/popper.js/dist/umd/popper.min.js ",
                                 "~/Admin/assets/libs/bootstrap/dist/js/bootstrap.min.js",
                                 "~/Admin/dist/js/notify.js")
                .WithEnvironmentOptions(bundleEnvironmentOptions);

                //toastr.min.css cdn den geliyor onu halletmeye calis
                manager.CreateCss("layout-login-css",
                                  "~/Admin/dist/css/style.min.css")
                .WithEnvironmentOptions(bundleEnvironmentOptions);

                #endregion

                #region Admin Layout
                //jquery-ui.js cdn den geliyor onu halletmeye calis
                //jquery-confirm.min.js cdn den geliyor onu halletmeye calis
                //toastr.min.js cdn den geliyor onu halletmeye calis
                //ckeditor.js  cdn den geliyor onu halletmeye calis (olmuyordu sanirim)
                manager.CreateJs("layout-admin-js",
                                 "~/js/site.js",
                                 "~/Admin/assets/libs/jquery/dist/jquery.min.js",
                                 "~/Admin/dist/js/tabulator.js",
                                 "~/Admin/dist/js/resize_table.js",
                                 "~/Admin/assets/libs/popper.js/dist/umd/popper.min.js",
                                 "~/Admin/assets/libs/bootstrap/dist/js/bootstrap.min.js",
                                 "~/Admin/dist/js/notify.js",
                                 "~/Admin/dist/js/app-style-switcher.js",
                                 "~/Admin/dist/js/feather.min.js",
                                 "~/Admin/assets/libs/perfect-scrollbar/dist/perfect-scrollbar.jquery.min.js",
                                 "~/Admin/dist/js/sidebarmenu.js",
                                 "~/Admin/dist/js/custom.min.js")
                .WithEnvironmentOptions(bundleEnvironmentOptions);

                //toastr.min.css cdn den geliyor onu halletmeye calis
                //jquery-ui.css cdn den geliyor onu halletmeye calis
                //jquery-confirm.min.css cdn den geliyor onu halletmeye calis
                manager.CreateCss("layout-admin-css",
                                  "~/Admin/dist/css/tabulator.min.css",
                                  "~/Admin/assets/libs/bootstrap/dist/css/tabulator_bootstrap.min.css",
                                  "~/Admin/dist/css/style.min.css")
                .WithEnvironmentOptions(bundleEnvironmentOptions);

                #endregion

                #region Main Layout

                /*
                 * jquery.min.js
                 * toastr.min.js
                 * tether.min.js
                 * bootstrap.min.js  cdn den iki adet bootstrap cagiriliyor
                 * jquery.touchSwipe.min.js
                 */
                manager.CreateJs("layout-main-js",
                                 "~/NewLayout/js/materialize.js",
                                 "~/NewLayout/js/bootstrap-touch-slider.js",
                                 "~/NewLayout/lib/easing/easing.min.js",
                                 "~/NewLayout/lib/mobile-nav/mobile-nav.js",
                                 "~/NewLayout/lib/wow/wow.min.js",
                                 "~/NewLayout/lib/waypoints/waypoints.min.js",
                                 "~/NewLayout/lib/counterup/counterup.min.js",
                                 "~/NewLayout/lib/owlcarousel/owl.carousel.min.js",
                                 "~/NewLayout/lib/isotope/isotope.pkgd.min.js",
                                 "~/NewLayout/lib/lightbox/js/lightbox.min.js",
                                 "~/NewLayout/js/main.js")
                .WithEnvironmentOptions(bundleEnvironmentOptions);


                /*
                 * google fonts
                 * bootstrap.min.css cdn den iki adet bootstrap cagiriliyor
                 * pro.fontawesome
                 * toastr.min.css
                 */

                //manager.CreateCss("layout-main-css",
                //     "~/NewLayout/css/materialize.min.css",
                //           "~/NewLayout/lib/font-awesome/css/font-awesome.min.css",
                //           "~/NewLayout/lib/animate/animate.min.css",
                //           "~/NewLayout/lib/ionicons/css/ionicons.min.css",
                //           "~/NewLayout/lib/owlcarousel/assets/owl.theme.default.min.css",
                //           "~/NewLayout/lib/owlcarousel/assets/owl.carousel.min.css",
                //           "~/NewLayout/lib/lightbox/css/lightbox.min.css",
                //           "~/NewLayout/vendor/icofont/icofont.min.css",
                //           "~/NewLayout/css/style.css")
                //.WithEnvironmentOptions(bundleEnvironmentOptions);

                #endregion
            });

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers()
                .RequireCors(MyAllowSpecificOrigins);

                endpoints.MapRazorPages();

                //endpoints.MapControllerRoute(
                //   name: "bloglist",
                //   pattern: "{blogPageName}.html",
                //   defaults: new { area = "", controller = "Home", action = "PetroBlog" },
                //   constraints: new { blogPageName = new BlogListConstraint(routeTable) }
                //   );

                //endpoints.MapControllerRoute(
                //    name: "blogDetail",
                //    pattern: "Blog/{blogPageName}/{id:int}/{title}",
                //    defaults: new { area = "", controller = "Detail", action = "BlogDetail" },
                //    constraints: new { blogPageName = new BlogDetailConstraint(routeTable) }
                //    );

                //endpoints.MapControllerRoute(
                //   name: "categoryDetail",
                //   pattern: "{pageTag}/{id:int}/{categoryName}",
                //   defaults: new { area = "", controller = "Detail", action = "CategoryDetail" },
                //   constraints: new { pageTag = new CategoryDetailConstraint(routeTable) }
                //   );

                //endpoints.MapControllerRoute(
                //   name: "productDetail",
                //   pattern: "{pageTag}/{produtname}/{id:int}",
                //   defaults: new { area = "", controller = "Detail", action = "BlogDetail" },
                //   constraints: new { pageTag = new ProductDetailConstraint(routeTable) }
                //   );

                endpoints.MapControllerRoute(
                    name: "areas",
                    pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");

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