Ejemplo n.º 1
0
        public void Configure
            (Microsoft.AspNetCore.Builder.IApplicationBuilder app,
            Microsoft.AspNetCore.Hosting.IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseSwagger();

            app.UseSwaggerUI(current =>
            {
                current.SwaggerEndpoint
                    (url: "/swagger/v1/swagger.json", name: "Banking Microservice V1");
            });

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            ConfigureEventBus(app);
        }
Ejemplo n.º 2
0
        public static void AddDefaultConfiguration(this Microsoft.AspNetCore.Builder.IApplicationBuilder applicationBuilder, IWebHostEnvironment webHostEnviroment)
        {
            if (webHostEnviroment.IsDevelopment())
            {
                applicationBuilder.UseDeveloperExceptionPage();
                applicationBuilder.UseDatabaseErrorPage();
            }
            else
            {
                applicationBuilder.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.
                applicationBuilder.UseHsts();
            }
            applicationBuilder.UseHttpsRedirection();
            applicationBuilder.UseStaticFiles();

            applicationBuilder.UseRouting();

            applicationBuilder.UseAuthentication();
            applicationBuilder.UseAuthorization();

            applicationBuilder.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapRazorPages();
            });
        }
Ejemplo n.º 3
0
        public void Configure
            (Microsoft.AspNetCore.Builder.IApplicationBuilder app,
            Microsoft.AspNetCore.Hosting.IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Ejemplo n.º 4
0
        public void Configure(Microsoft.AspNetCore.Builder.IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            // app.UseHttpsRedirection();
            app.UseSerilogRequestLogging(); // <-- Add this line
            app.UseRouting();

            // use the package https://github.com/prometheus-net/prometheus-net and https://github.com/djluck/prometheus-net.DotNetRuntime (See program.cs) to collect metric we can expose the SBA
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapHealthChecks("/health");
                endpoints.MapControllers();
            });
        }
Ejemplo n.º 5
0
        } // End Sub ConfigureServices

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(
            Microsoft.AspNetCore.Builder.IApplicationBuilder app
            , Microsoft.AspNetCore.Hosting.IWebHostEnvironment env
            , Microsoft.Extensions.Logging.ILoggerFactory loggerFactory)
        {
            // https://gunnarpeipman.com/aspnet-core-syslog/
            // https://stackoverflow.com/questions/20951667/how-to-write-to-kiwi-syslog-server-log-c-
            // https://github.com/emertechie/SyslogNet/tree/master/SyslogNet.Client/Transport
            // https://maxbelkov.github.io/visualsyslog/
            loggerFactory.AddSyslog("192.168.210.56", 514);


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



            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.UseDefaultFiles(
                new Microsoft.AspNetCore.Builder.DefaultFilesOptions()
            {
                DefaultFileNames = new System.Collections.Generic.List <string>()
                {
                    "index.htm", "index.html"
                }
            }
                );


            app.UseStaticFiles(
                new Microsoft.AspNetCore.Builder.StaticFileOptions()
            {
                ServeUnknownFileTypes = true,
                DefaultContentType    = "application/octet-stream",
                ContentTypeProvider   = new ExtensionContentTypeProvider(),

                OnPrepareResponse = delegate(Microsoft.AspNetCore.StaticFiles.StaticFileResponseContext context)
                {
                    // https://stackoverflow.com/questions/49547/how-do-we-control-web-page-caching-across-all-browsers

                    // The Cache-Control is per the HTTP 1.1 spec for clients and proxies
                    // If you don't care about IE6, then you could omit Cache-Control: no-cache.
                    // (some browsers observe no-store and some observe must-revalidate)
                    context.Context.Response.Headers["Cache-Control"] = "no-cache, no-store, must-revalidate, max-age=0";
                    // Other Cache-Control parameters such as max-age are irrelevant
                    // if the abovementioned Cache-Control parameters (no-cache,no-store,must-revalidate) are specified.


                    // Expires is per the HTTP 1.0 and 1.1 specs for clients and proxies.
                    // In HTTP 1.1, the Cache-Control takes precedence over Expires, so it's after all for HTTP 1.0 proxies only.
                    // If you don't care about HTTP 1.0 proxies, then you could omit Expires.
                    context.Context.Response.Headers["Expires"] = "-1, 0, Tue, 01 Jan 1980 1:00:00 GMT";

                    // The Pragma is per the HTTP 1.0 spec for prehistoric clients, such as Java WebClient
                    // If you don't care about IE6 nor HTTP 1.0 clients
                    // (HTTP 1.1 was introduced 1997), then you could omit Pragma.
                    context.Context.Response.Headers["pragma"] = "no-cache";


                    // On the other hand, if the server auto-includes a valid Date header,
                    // then you could theoretically omit Cache-Control too and rely on Expires only.

                    // Date: Wed, 24 Aug 2016 18:32:02 GMT
                    // Expires: 0

                    // But that may fail if e.g. the end-user manipulates the operating system date
                    // and the client software is relying on it.
                    // https://stackoverflow.com/questions/21120882/the-date-time-format-used-in-http-headers
                }     // End Sub OnPrepareResponse
            }
                );



            app.UseRouting();


            // https://stackoverflow.com/questions/60791843/changing-routedata-in-asp-net-core-3-1-in-middleware
            app.Use(
                async delegate(Microsoft.AspNetCore.Http.HttpContext context, System.Func <System.Threading.Tasks.Task> next)
            {
                string url           = context.Request.Headers["HOST"];
                string[] splittedUrl = url.Split('.');

                if (splittedUrl != null && (splittedUrl.Length > 0))
                {
                    context.GetRouteData().Values.Add("Host", splittedUrl[0]);
                    // context.GetRouteData().Values["controller"] = "test";
                }     // End if (splittedUrl != null && (splittedUrl.Length > 0))


                // if (splittedUrl != null && (splittedUrl.Length > 0 && splittedUrl[0] == "admin"))
                // {
                //     context.GetRouteData().Values.Add("area", "Admin");
                // }


                // Call the next delegate/middleware in the pipeline
                await next();
            }
                );


            app.UseAuthorization();

            /*
             * app.UseMvc(
             *  delegate(IRouteBuilder routes)
             *  {
             *      routes.DefaultHandler = new Microsoft.AspNetCore.Mvc.Routing.AreaRouter();
             *      // routes.MapRoute(name: "areaRoute", template: "{controller=Home}/{action=Index}");
             *  }
             * );
             */



            // https://stackoverflow.com/questions/278668/is-it-possible-to-make-an-asp-net-mvc-route-based-on-a-subdomain

            // https://stackoverflow.com/questions/57172884/mapping-subdomains-to-areas-in-asp-net-core-3
            app.UseEndpoints(
                delegate(Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints)
            {
                endpoints.MapDynamicControllerRoute <SearchValueTransformer>("search/{**product}");
                // de.bar.int:5001/

                endpoints.MapControllerRoute(
                    name: "default",
                    // pattern: "{controller=Home}/{action=Index}/{id?}",
                    // pattern: "{controller=Blog}/{action=Index}/{id?}",
                    pattern: "{controller=Blog}/{action=ShowEntry}/{id?}"
                    );
            }
                );
        } // End Sub Configure