Пример #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(Microsoft.AspNetCore.Builder.IApplicationBuilder app, IHostingEnvironment env, DataInitializer initializer)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // 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.UseAuthentication();


            app.UseCors("AllowAllOrigins");


            app.UseHttpsRedirection();
            app.UseMvc();

            app.UseSwaggerUi3();

            app.UseSwagger();


            initializer.InitializeData().Wait();
        }
Пример #2
0
        // 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.IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

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

            // به برنامه اضافه کنیم، به این دستور نیاز داریم Area در صورتی که بخواهیم
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "areas",
                    template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
                    );
            });
        }
Пример #3
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();
            });
        }
Пример #4
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)
        {
            InitializeContainer(app);

            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            var rewriteOptions = new RewriteOptions()
                                 .AddRewrite("^vocabulary(?!Page)", "index.html", true); // redirect vocabulary page to main page and let angular handle routing

            app.UseRewriter(rewriteOptions);

            ConfigureAuth(app);

            app.UseWebSockets()
            .UseSignalR()
            .UseDefaultFiles(new DefaultFilesOptions())
            .UseStaticFiles()
            .UseMvc()
            .UseSimpleInjectorAspNetRequestScoping(container);

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            InitializeMapper();
            SetUpDbConnection();
            StartInteractionWithUser();
        }
Пример #5
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);
        }
Пример #6
0
        // 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.IHostingEnvironment env,
            Microsoft.Extensions.Logging.ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug(minLevel: LogLevel.Trace);

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

            app.UseStaticFiles();

            // **************************************************
            // Note:
            // نکته مهم آن است که محل نوشتن دستور ذیل بسیار
            // اهمیت دارد، اگر بعد از دستور بعدی نوشته شود، عمل نمی‌کند
            // Note: For all Actions of Controllers
            app.UseCors("AllowSpecificOrigin");
            // **************************************************

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{culture=fa-IR}/{controller=Home}/{action=Index}/{id?}");
            });
        }
Пример #7
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(Microsoft.AspNetCore.Builder.IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

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

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

            DefaultData.Create(app.ApplicationServices);
        }
Пример #8
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(Microsoft.AspNetCore.Builder.IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

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

            app.UseStaticFiles();

            app.UseIdentity();

            // Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715
            app.UseSession();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            app.UseStatusCodePagesWithRedirects("Account/AccessDenied");

            DatabaseInitializer.Initialize(app.ApplicationServices);
        }
Пример #9
0
 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
 public void Configure(Microsoft.AspNetCore.Builder.IApplicationBuilder app, IHostingEnvironment env)
 {
     if (env.IsDevelopment())
     {
         app.UseDeveloperExceptionPage();
     }
     app.UseJimu(_host);
     _host.Run();
 }
Пример #10
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(Microsoft.AspNetCore.Builder.IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IServiceProvider serviceProvider, RoleManager <WebRole> roleManager, UserManager <WebUser> userManager)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions {
                    HotModuleReplacement = true,
                    //HotModuleReplacementEndpoint = "/dist/__webpack_hmr",
                    ReactHotModuleReplacement = true
                });
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            // Add custom middleweara for thumbnails and images.
            app.UseThumbnailHandler();
            app.UseImageHandler();

            // app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseAuthentication();

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint.
            app.UseSwagger();

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

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

                routes.MapSpaFallbackRoute(
                    name: "spa-fallback",
                    defaults: new { controller = "Home", action = "Index" });
            });

            CreateRoles(roleManager, userManager);
        }
Пример #11
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(Microsoft.AspNetCore.Builder.IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // 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.UseMvc();
        }
Пример #12
0
        public void Configure
            (Microsoft.AspNetCore.Builder.IApplicationBuilder app,
            Microsoft.AspNetCore.Hosting.IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseExceptionHandlingMiddleware();

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Пример #13
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(Microsoft.AspNetCore.Builder.IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            // start jimu client host;
            var host = new ApplicationClientBuilder(new ContainerBuilder())
                       //.UseConsulForDiscovery(new Jimu.Client.Discovery.ConsulIntegration.ConsulOptions("127.0.0.1", 8500, "JimuService-"))
                       //.UseDotNettyForTransfer()
                       //.UseHttpForTransfer()
                       //.UsePollingAddressSelector()
                       .Build();

            app.UseJimu(host);
            host.Run();
        }
Пример #14
0
        // 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.IHostingEnvironment env)
        {
            app.UseDeveloperExceptionPage();
            app.UseStatusCodePages();
            app.UseStaticFiles();
            //app.UseMvcWithDefaultRoute(); I am going to replace this with app.UseMvc() and passing to this one my route ;

            app.UseAuthentication();
            app.UseMvc(routes =>
            {
                routes.MapRoute(

                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}"//this template is going to be use to match incoming request with this pattern
                    );
            }
                       );
            // In complex application we can use several routes by calling MapRoute several times with different routes;
        }
Пример #15
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();
            });
        }
Пример #16
0
        }                                                                                                                                                                                                                                                                                        // makes EFProductRepository take the place of IProductRepository in the code

        //This method is called after the 'webHost.Run();' line in the Program.cs is called.
        //when called, two parameters are passed in. They are app and env.
        //sets up stuff
        //doesn't return anything
        public void Configure(Microsoft.AspNetCore.Builder.IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseStatusCodePages();
            }
            else
            {
                app.UseExceptionHandler("/Error");
            }
            app.UseStaticFiles();
            app.UseSession();
            app.UseAuthentication();
            //next line routes requests to the application root to the appropriate controller based on the url
            app.UseMvc(routes => {
                routes.MapRoute(
                    name: null,
                    template: "{category}/Page{productPage:int}",
                    defaults: new { controller = "Product", action = "List" });
                routes.MapRoute(
                    name: null,
                    template: "Page{productPage:int}",
                    defaults: new { controller = "Product", action = "List", productPage = 1 });
                routes.MapRoute(
                    name: null,
                    template: "{category}",
                    defaults: new { controller = "Product", action = "List", productPage = 1 });
                routes.MapRoute(
                    name: null,
                    template: "",
                    defaults: new { controller = "Product", action = "List", productPage = 1 });
                routes.MapRoute(
                    name: null,
                    template: "{controller}/{action}/{id?}");
            });
        }
Пример #17
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
Пример #18
0
        // 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.IHostingEnvironment env)
        {
            app.UseForwardedHeaders(new ForwardedHeadersOptions
            {
                ForwardedHeaders = Microsoft.AspNetCore.HttpOverrides.ForwardedHeaders.XForwardedFor
                                   | Microsoft.AspNetCore.HttpOverrides.ForwardedHeaders.XForwardedProto
            });



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


            app.UseDefaultFiles(
                new Microsoft.AspNetCore.Builder.DefaultFilesOptions()
            {
                DefaultFileNames = new System.Collections.Generic.List <string>()
                {
                    "index.htm", "index.html", "slick.htm"
                }
            }
                );


            app.UseStaticFiles(new 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
                }
            });

            Microsoft.AspNetCore.Builder.WebSocketOptions webSocketOptions = new Microsoft.AspNetCore.Builder.WebSocketOptions()
            {
                KeepAliveInterval = System.TimeSpan.FromSeconds(120),
                ReceiveBufferSize = 4 * 1024
            };


            app.UseWebSockets(webSocketOptions);
            app.UseOpenFolderOrFileExtensions("/OpenFolder");
            app.UseRansackSearch("/ransack");
            app.UseRansackSearchAndReplace("/sar");
            app.UseTable("/table");
            app.UseFileContents("/textfile");

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