Beispiel #1
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())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

#if (enable - gnu - pratchett)
            app.GnuTerryPratchett();
#endif
#if (enable - secure - headers)
            app.UseSecureHeadersMiddleware(SecureHeadersMiddlewareExtensions.BuildDefaultConfiguration());
#endif

            app.UseStaticFiles();

            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Beispiel #2
0
        public void Configure(IApplicationBuilder app,
                              IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.GnuTerryPratchett();
            app.UseSecureHeadersMiddleware(SecureHeadersMiddlewareExtensions.BuildDefaultConfiguration());
            app.UseMvc();
        }
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())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                app.UseSecureHeadersMiddleware(
                    SecureHeadersMiddlewareExtensions.BuildDefaultConfiguration()
                    );
            }

            app.UseForwardedHeaders(new ForwardedHeadersOptions
            {
                ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
            });

            app.UseStaticFiles();
            app.UseSpaStaticFiles();

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

            app.UseSpa(spa =>
            {
                // To learn more about options for serving an Angular SPA from ASP.NET Core,
                // see https://go.microsoft.com/fwlink/?linkid=864501

                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseAngularCliServer(npmScript: "start");
                }
            });
        }
Beispiel #4
0
        private void Configure(
            IApplicationBuilder app,
            IWebHostEnvironment env,
            ILoggerFactory loggerFactory)
        {
            var diagnosticListener          = app.ApplicationServices.GetService <DiagnosticListener>();
            var logDiagnosticListenerLogger = loggerFactory.CreateLogger <LogDiagnosticListener>();

            diagnosticListener.SubscribeWithAdapter(new LogDiagnosticListener(logDiagnosticListenerLogger));

            var logger = loggerFactory.CreateLogger <BaseStartup>();

            logger.LogInformation("Starting configuration");

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

            app.UseBlockingDetection();
            app.UseProblemDetails();

            var version = new Version(0, 1, 1, 9999);

            /*
             * ApmApplicationStartHelper.Configure(Configuration, app, version);
             */

            var secureHeadersMiddlewareConfiguration = SecureHeadersMiddlewareExtensions.BuildDefaultConfiguration();

            app.UseSecureHeadersMiddleware(secureHeadersMiddlewareConfiguration);

            app.UseStaticFiles();

            app.UseAuditMiddleware(_ => _
                                   .FilterByRequest(rq => !rq.Path.Value.EndsWith("favicon.ico", StringComparison.OrdinalIgnoreCase))
                                   .WithEventType("{verb}:{url}")
                                   .IncludeHeaders()
                                   .IncludeRequestBody()
                                   .IncludeResponseBody());
            var fileDataProvider = Audit.Core.Configuration.DataProvider as FileDataProvider;

            if (fileDataProvider != null)
            {
                // this was done so files don't get added to git
                // as the visual studio .gitignore ignores log folders.
                fileDataProvider.DirectoryPath = "log";
            }

            _miniProfilerApplicationStartHelper.ConfigureApplication(app);

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "get",
                    template: "api/{controller}/{id?}",
                    defaults: new { action = "GetAsync" },
                    constraints: new RouteValueDictionary(new { httpMethod = new HttpMethodRouteConstraint("GET") }));
                routes.MapRoute(
                    name: "post",
                    template: "api/{controller}",
                    defaults: new { action = "PostAsync" },
                    constraints: new RouteValueDictionary(new { httpMethod = new HttpMethodRouteConstraint("POST") }));
                routes.MapRoute(
                    name: "post",
                    template: "api/{controller}/{id}",
                    defaults: new { action = "PutAsync" },
                    constraints: new RouteValueDictionary(new { httpMethod = new HttpMethodRouteConstraint("PUT") }));
                routes.MapRoute(
                    name: "delete",
                    template: "api/{controller}/{id}",
                    defaults: new { action = "DeleteAsync" },
                    constraints: new RouteValueDictionary(new { httpMethod = new HttpMethodRouteConstraint("DELETE") }));
            });

            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
            });
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public static void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseCustomSerilogRequestLogging();

            app.UseRouting();
            app.UseStaticFiles();
            if (!Directory.Exists("./Images"))
            {
                Directory.CreateDirectory("./Images");
            }
            app.UseStaticFiles(new StaticFileOptions
            {
                FileProvider = new PhysicalFileProvider(
                    Path.Combine(env.ContentRootPath, "Images")),
                RequestPath = "/Images"
            });

            app.UseDirectoryBrowser(new DirectoryBrowserOptions
            {
                FileProvider = new PhysicalFileProvider(
                    Path.Combine(env.ContentRootPath, "Images")),
                RequestPath = "/Images"
            });
            app.UseStaticFiles(new StaticFileOptions
            {
                FileProvider = new PhysicalFileProvider(
                    Path.Combine(env.ContentRootPath, "Documents")),
                RequestPath = "/Documents"
            });

            app.UseDirectoryBrowser(new DirectoryBrowserOptions
            {
                FileProvider = new PhysicalFileProvider(
                    Path.Combine(env.ContentRootPath, "Documents")),
                RequestPath = "/Documents"
            });

            app.UseCors("AllowAll");

            app.UseApiDoc();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
            WebHelpers.Configure(app.ApplicationServices.GetRequiredService <IHttpContextAccessor>());

            //added request logging

            app.UseHttpsRedirection();
            app.UseMiddleware <JwtMiddleware>();
            app.UseMiddleware <ApiLoggingMiddleware>();

            app.UseResponseCompression();
            app.UseAuthentication();
            app.UseAuthorization();
            app.UseSecureHeadersMiddleware(SecureHeadersMiddlewareExtensions.BuildDefaultConfiguration());
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
            // app.UseCors(options => options.AllowAnyOrigin());
        }
Beispiel #6
0
        private void Configure(
            IApplicationBuilder app,
            IWebHostEnvironment env,
            ILoggerFactory loggerFactory)
        {
            var diagnosticListener          = app.ApplicationServices.GetService <DiagnosticListener>();
            var logDiagnosticListenerLogger = loggerFactory.CreateLogger <LogDiagnosticListener>();

            _ = diagnosticListener.SubscribeWithAdapter(new LogDiagnosticListener(logDiagnosticListenerLogger));

            var logger = loggerFactory.CreateLogger <BaseStartup>();

#pragma warning disable CA1848 // Use the LoggerMessage delegates
            logger.LogInformation("Starting configuration");
#pragma warning restore CA1848 // Use the LoggerMessage delegates

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

            _ = app.UseBlockingDetection();

            _ = app.UseProblemDetails();

            var version = new Version(0, 1, 1, 9999);

            /*
             * ApmApplicationStartHelper.Configure(Configuration, app, version);
             */

            var secureHeadersMiddlewareConfiguration = SecureHeadersMiddlewareExtensions.BuildDefaultConfiguration();
            _ = app.UseSecureHeadersMiddleware(secureHeadersMiddlewareConfiguration);

            _ = app.UseStaticFiles();

            _ = app.UseAuditMiddleware(_ => _
                                       .FilterByRequest(rq =>
            {
                var pathValue = rq.Path.Value;
                return(pathValue != null && !pathValue.EndsWith("favicon.ico", StringComparison.OrdinalIgnoreCase));
            })
                                       .WithEventType("{verb}:{url}")
                                       .IncludeHeaders()
                                       .IncludeRequestBody()
                                       .IncludeResponseHeaders()
                                       .IncludeResponseBody());

            if (Audit.Core.Configuration.DataProvider is FileDataProvider fileDataProvider)
            {
                // this was done so files don't get added to git
                // as the visual studio .gitignore ignores log folders.
                fileDataProvider.DirectoryPath = "log";
            }

            /*
             * _miniProfilerApplicationStartHelper.ConfigureApplication(app);
             */

            if (_useSwagger)
            {
                _ = app.UseSwagger();
                _ = app.UseSwaggerUI(c =>
                {
                    c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
                });
            }

            _ = app.UseRouting();

            _ = app.UseEndpoints(endpoints =>
            {
                _ = endpoints.MapControllerRoute(
                    "get",
                    "api/{controller}/{id?}",
                    new { action = "Get" },
                    new RouteValueDictionary(new { httpMethod = new HttpMethodRouteConstraint("GET") }));
            });

            OnConfigure(app, env, loggerFactory);
        }