Beispiel #1
0
 private static bool CheckHostingEnvironmentIsProductionOrStagingOrDevelopment(
     Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnvironment)
 {
     return(hostingEnvironment.IsProduction() ||
            hostingEnvironment.IsStaging() ||
            hostingEnvironment.IsDevelopment());
 }
Beispiel #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IHostingEnvironment env, Microsoft.AspNetCore.Hosting.IApplicationLifetime appLifetime, IServiceProvider serviceProvider)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
                {
                    HotModuleReplacement = true
                });
            }
            else if (env.IsStaging())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseDeveloperExceptionPage();
                //app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Beispiel #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)
        {
            if (env.IsDevelopment() || env.IsStaging())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseSwagger();

            app.UseSwaggerUi3(settings =>
            {
                settings.Path = "/api";
                //settings.DocumentPath = "/api/specification.json";
            });

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action=Index}/{id?}");
            });
            app.UseStaticFiles();
            app.UseDirectoryBrowser();
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IOptions <RouteOptions> routeOptionsAccessor, IDasBlogSettings dasBlogSettings)
        {
            (var siteOk, string siteError) = RepairSite(app);
            if (env.IsDevelopment() || env.IsStaging())
            {
                app.UseDeveloperExceptionPage();
                //app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/home/error");
            }

            if (!siteOk)
            {
                app.Run(async context => await context.Response.WriteAsync(siteError));
                return;
            }

            var options = new RewriteOptions()
                          .AddIISUrlRewrite(env.ContentRootFileProvider, @"Config/IISUrlRewrite.xml");

            app.UseRewriter(options);


            //if you've configured it at /blog or /whatever, set that pathbase so ~ will generate correctly
            Uri    rootUri = new Uri(dasBlogSettings.SiteConfiguration.Root);
            string path    = rootUri.AbsolutePath;

            //Deal with path base and proxies that change the request path
            //https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-2.2#deal-with-path-base-and-proxies-that-change-the-request-path
            if (path != "/")
            {
                app.Use((context, next) =>
                {
                    context.Request.PathBase = new PathString(path);
                    return(next.Invoke());
                });
            }
            app.UseForwardedHeaders();

            app.UseStaticFiles();
            app.UseStaticFiles(new StaticFileOptions()
            {
                FileProvider = new PhysicalFileProvider(Path.Combine(GetDataRoot(env), binariesPath.TrimStart('/'))),
                RequestPath  = binariesPath
            });

            app.UseStaticFiles(new StaticFileOptions
            {
                FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath, "Themes")),
                RequestPath  = "/theme"
            });

            app.UseAuthentication();
            app.Use(PopulateThreadCurrentPrincipalForMvc);
            //We'll replace this when we move to ASP.NET Core 2.2+ LTS
            app.Map("/healthcheck", api =>
            {
                api.Run(async(context) =>
                {
                    await context.Response.WriteAsync("Healthy");
                });
            });
            app.UseMvc(routes =>
            {
                if (routeOptionsAccessor.Value.EnableTitlePermaLinkUnique)
                {
                    routes.MapRoute(
                        "Original Post Format",
                        "~/{year:int}/{month:int}/{day:int}/{posttitle}.aspx",
                        new { controller = "BlogPost", action = "Post", posttitle = "" });

                    routes.MapRoute(
                        "New Post Format",
                        "~/{year:int}/{month:int}/{day:int}/{posttitle}",
                        new { controller = "BlogPost", action = "Post", postitle = "" });
                }
                else
                {
                    routes.MapRoute(
                        "Original Post Format",
                        "~/{posttitle}.aspx",
                        new { controller = "BlogPost", action = "Post", posttitle = "" });

                    routes.MapRoute(
                        "New Post Format",
                        "~/{posttitle}",
                        new { controller = "BlogPost", action = "Post", postitle = "" });
                }
                routes.MapRoute(
                    name: "default",
                    template: "~/{controller=Home}/{action=Index}/{id?}");
            });
        }