Example #1
0
        public static IApplicationBuilder UseNetCoreCMS(this IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider, ILoggerFactory loggerFactory)
        {
            ResourcePathExpendar.RegisterStaticFiles(env, app, GlobalContext.Modules, GlobalContext.Themes);

            //app.UseThemeActivator(env, loggerFactory);
            //app.UseModuleActivator(env, _mvcBuilder, _services, loggerFactory);

            app.UseResponseCaching(); //Use this attrib for cache [ResponseCache(Duration = 20)]
            app.UseResponseCompression();
            app.UseSession();
            app.UseStaticFiles();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            GlobalContext.App = app;

            if (SetupHelper.IsDbCreateComplete)
            {
                app.UseAuthentication();

                NccWebSiteWidgetService nccWebsiteWidgetServices = serviceProvider.GetService <NccWebSiteWidgetService>();
                NccWebSiteService       nccWebsiteService        = serviceProvider.GetService <NccWebSiteService>();
                NccMenuService          menuServic = serviceProvider.GetService <NccMenuService>();

                GlobalContext.WebSite        = nccWebsiteService.LoadAll().FirstOrDefault();
                ThemeHelper.WebSite          = GlobalContext.WebSite;
                GlobalContext.WebSiteWidgets = nccWebsiteWidgetServices.LoadAll();
                GlobalContext.Menus          = menuServic.LoadAllSiteMenus();
            }

            app.UseMaintenance();

            if (SetupHelper.IsAdminCreateComplete)
            {
                app.UseRequestLocalization(new RequestLocalizationOptions
                {
                    DefaultRequestCulture = new RequestCulture(SetupHelper.Language),
                    SupportedCultures     = SupportedCultures.Cultures,
                    SupportedUICultures   = SupportedCultures.Cultures
                });
            }

            return(app);
        }
        public static IApplicationBuilder UseThemeActivator(this IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            return app.Use((context, next) =>
            {
                var _themeManager = new ThemeManager();
                var themeFolder = Path.Combine(env.ContentRootPath, NccInfo.ThemeFolder);
                GlobalContext.Themes = _themeManager.ScanThemeDirectory(themeFolder);

                ResourcePathExpendar.RegisterStaticFiles(env, app, GlobalContext.Modules, GlobalContext.Themes);
                
                return next();
            });            
        }
Example #3
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(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            _themeManager = new ThemeManager(loggerFactory);
            var themeFolder = Path.Combine(env.ContentRootPath, NccInfo.ThemeFolder);

            GlobalConfig.Themes = _themeManager.ScanThemeDirectory(themeFolder);

            ResourcePathExpendar.RegisterStaticFiles(env, app, GlobalConfig.Modules, GlobalConfig.Themes);

            //app.UseThemeActivator(env, loggerFactory);
            //app.UseModuleActivator(env, _mvcBuilder, _services, loggerFactory);

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
                //app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();
            GlobalConfig.App = app;

            if (SetupHelper.IsDbCreateComplete)
            {
                app.UseIdentity();

                NccWebSiteWidgetService nccWebsiteWidgetServices = _serviceProvider.GetService <NccWebSiteWidgetService>();
                NccWebSiteService       nccWebsiteService        = _serviceProvider.GetService <NccWebSiteService>();
                NccMenuService          menuServic = _serviceProvider.GetService <NccMenuService>();

                GlobalConfig.WebSite        = nccWebsiteService.LoadAll().FirstOrDefault();
                GlobalConfig.WebSiteWidgets = nccWebsiteWidgetServices.LoadAll();
                GlobalConfig.Menus          = menuServic.LoadAllSiteMenus();
            }

            app.UseSession();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
                routes.MapRoute(
                    name: "cmsPage",
                    template: "{slug}",
                    defaults: new { controller = "CmsPage", action = "Index" });
                routes.MapRoute(
                    name: "blogPost",
                    template: "Post/{slug}",
                    defaults: new { controller = "Post", action = "Index" });
                routes.MapRoute(
                    name: "blogCategory",
                    template: "{slug}",
                    defaults: new { controller = "Category", action = "Index" });
            });
        }