Ejemplo n.º 1
0
        private void AppendBlogSitemap(List <SitemapNode> nodes)
        {
            string blogSitemap = BlogLocationUtil.SitemapLocation(this.environment);

            if (!File.Exists(blogSitemap))
            {
                m_logger.LogWarning("Not including Blog's sitemap as file does not exist");
                return;
            }
            try
            {
                XmlSerializer ser          = new XmlSerializer(typeof(Urlset), "http://www.sitemaps.org/schemas/sitemap/0.9");
                FileStream    myFileStream = new FileStream(blogSitemap, FileMode.Open);
                var           urls         = ((Urlset)ser.Deserialize(myFileStream)).urls;
                foreach (var url in urls)
                {
                    nodes.Add(new SitemapNode()
                    {
                        Url             = url.loc,
                        Frequency       = SitemapFrequency.Monthly,
                        Priority        = DefaultPriority,
                        LastModifiedRaw = url.lastmod,
                    });
                }
            }
            catch (Exception e)
            {
                m_logger.LogError(e, "Error when trying to add blog's sitemap to the main one");
            }
        }
Ejemplo n.º 2
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();
            m_logger = loggerFactory.CreateLogger <Startup>();

            DefaultFilesOptions options = new DefaultFilesOptions();

            //options.DefaultFileNames.Clear();
            options.DefaultFileNames.Add("index.html");
            app.UseDefaultFiles(options);

            app.UseDefaultFiles(new DefaultFilesOptions()
            {
                FileProvider = new PhysicalFileProvider(
                    BlogLocationUtil.GetBlogFilesLocation(env)),
                RequestPath = new PathString("/blog")
            });

            app.UseStaticFiles();
            app.UseStaticFiles(new StaticFileOptions
            {
                FileProvider = new PhysicalFileProvider(
                    BlogLocationUtil.GetBlogFilesLocation(env)),
                RequestPath       = "/blog",
                OnPrepareResponse = ctx =>
                {
                    // Requires the following import:
                    // using Microsoft.AspNetCore.Http;
                    ctx.Context.Response.Headers.Append("Cache-Control", "public,max-age=600");
                },
            }
                               );

            //app.UseApplicationInsightsRequestTelemetry();

            if (env.IsDevelopment())
            {
                m_logger.LogInformation("Running in development mode");
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
                app.UseBrowserLink();
            }
            else
            {
                m_logger.LogInformation("Running in production mode");
                app.UseExceptionHandler("/Home/Error");
            }

            //app.UseStatusCodePagesWithRedirects("~/errors/code/{0}");

            app.UseSecurityHeadersMiddleware(new SecurityHeadersBuilder()
                                             .AddDefaultSecurePolicy()
                                             );

            //app.UseApplicationInsightsExceptionTelemetry();

            app.UseAuthentication();

            //AddExternalAuthentication(app);

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "showTest",
                    template: "{controller=Benchmarks}/{action=Show}/{id}/{version}/{name?}");

                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }