示例#1
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                loggerFactory.AddConsole(Configuration.GetSection("Logging"));
                loggerFactory.AddDebug();

                app.UseDeveloperExceptionPage();
            }

            #region Logging to DB

            IDictionary <String, LogLevel> contextLogFilter = Configuration
                                                              .GetSection("Logging:Context:LogLevel").GetChildren()
                                                              .Where(i => !i.Key.Equals("Default", StringComparison.OrdinalIgnoreCase))
                                                              .Select(i =>
            {
                if (Enum.TryParse(i.Value, true, out LogLevel level))
                {
                    return(new KeyValuePair <String, LogLevel>(i.Key, level));
                }

                return(new KeyValuePair <String, LogLevel>(i.Key, LogLevel.None));
            })
                                                              .ToDictionary(k => k.Key, v => v.Value);

            LogLevel minLevel = Configuration.GetValue <LogLevel>("Logging:Context:LogLevel:Default");
            if ((contextLogFilter?.Count ?? 0) > 0)
            {
                loggerFactory.AddContext((category, logLevel) => {
                    if (contextLogFilter
                        .Any(f => category.Equals(f.Key, StringComparison.OrdinalIgnoreCase) ||
                             category.StartsWith(f.Key, StringComparison.OrdinalIgnoreCase)))
                    {
                        return(logLevel >= contextLogFilter
                               .First(f => category.Equals(f.Key, StringComparison.OrdinalIgnoreCase) ||
                                      category.StartsWith(f.Key, StringComparison.OrdinalIgnoreCase)).Value);
                    }

                    return(logLevel >= minLevel);
                });
            }
            else
            {
                loggerFactory.AddContext(minLevel);
            }

            #endregion

            app.UseStaticFiles();

            app.UseMvc();
        }
示例#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.AddContext(LogLevel.Error);
            app.UseCors("CorsPolicy");
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }
            app.UseResponseCompression();
            app.UseHttpsRedirection();
            app.UseMvc();
            app.UseHangfireServer();
            app.UseHangfireDashboard();

            // Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger();

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
            // specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
            });
        }
示例#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, ILoggerFactory loggerFactory)
        {
            //var logWriter = new SqlServerLogWriter(Configuration.GetConnectionString("Logging"));
            //loggerFactory.AddConsole(Configuration.GetSection("Logging"))
            //            .AddDLogger(Configuration.GetSection("Logging"), logWriter);

            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();
            loggerFactory.AddContext(LogLevel.Information, Configuration.GetConnectionString("LoggerDatabase"));
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
示例#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, IServiceProvider provider, ILoggerFactory loggingFactory, ApplicationDbContext ctxt)
        {
            loggingFactory.AddContext(LogLevel.Error, ctxt);

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

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

            app.UseAuthentication();

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

                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
示例#5
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, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(_configuration.GetSection("Logging"));
            loggerFactory.AddDebug();
            loggerFactory.AddContext(LogLevel.Information, _configuration.GetConnectionString("LoggerDatabase"));
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            // Swagger- autodocument
            app.UseStaticFiles();
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Goober Service");
            });

            // JWT
            // app.UseMiddleware<AuthenticationMiddleware>(new JsonConfiguration());
            app.UseAuthentication();

            app.UseCors("CorsPolicy");

            app.UseMvc();
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider,
                              ILoggerFactory loggingRactory, EventureDbContext context)
        {
            //var loggingFactory = serviceProvider.GetService<LoggerFactory>();
            loggingRactory.AddContext(LogLevel.Error, context);

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }
            var dbContext = serviceProvider.GetService <EventureDbContext>();

            dbContext.Database.Migrate();

            app.UseSeedDataMiddleware();
            Seeder.Seed(serviceProvider);
            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{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(IApplicationBuilder app, IHostEnvironment env, ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            app.UseStaticFiles();
            app.UseRouting();
            app.UseCors("EnablingCors");
            app.UseHttpsRedirection();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Divulgação ONG's");
            });
            loggerFactory.AddContext(LogLevel.Warning, new LogRepository(new LogContext(Configuration.GetConnectionString("ST_POSTGRES_LOG"))));
        }
示例#8
0
        /// <summary>
        /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        /// </summary>
        /// <param name="app"></param>
        /// <param name="env"></param>
        /// <param name="loggerFactory"></param>
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();
            loggerFactory.AddContext(LogLevel.Information, Configuration.GetConnectionString("MentorsAcademyLogDatabase"));

            var jwtAppSettingOptions = Configuration.GetSection(nameof(JwtIssuerOptions));
            var connectionString     = ConfigurationExtensions.GetConnectionString(this.Configuration, "MentorsAcademyLogDatabase");

            if (!String.IsNullOrEmpty(connectionString))
            {
                app.UseLoggingMiddleware(new LoggingMiddlewareOptions {
                    _connectionString = connectionString
                });
            }

            app.UseAuthentication();

            app.UseMvc();

            app.UseDefaultFiles();
            app.UseStaticFiles();
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Academy.Mentors API V1");
                c.DocExpansion("none");
            });
        }
示例#9
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)
        {
            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.UseStaticFiles();
            app.UseHttpsRedirection();


            app.UseMvc();

            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                //启用中间件服务对swagger-ui,指定Swagger JSON终结点
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "MikesBank API");
                c.RoutePrefix = string.Empty;
                c.InjectJavascript("Scripts/SwaggerUI/swagger_lang.js");
                //D:\Github\00 lanlive\MikesBank\MikesBank\Scripts\SwaggerUI\swagger_lang.js
            });
            app.UseAPIResponseWrapperMiddleware();
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddContext(LogLevel.Information, Configuration.GetConnectionString("MyDatabase"));
        }
示例#10
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            app.UseMiddleware <LogExceptionHandlerMiddleware>();

            Enum.TryParse(Configuration["LogLevel"], true, out LogLevel logLevel);
            loggerFactory.AddConsole(logLevel);
            loggerFactory.AddDebug(logLevel);
            loggerFactory.AddContext(logLevel, Configuration.GetConnectionString("DefaultConnection"));

            if (env.IsDevelopment())
            {
                loggerFactory.AddFile(Path.Combine(Directory.GetCurrentDirectory(), "logger.txt"), logLevel);
            }

            app.UseDefaultFiles();

            app.UseAuthentication();

            app.UseStaticFiles();

            app.UseSwagger();

            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Web V1");
            });

            app.UseMvcWithDefaultRoute();

            app.Run(async(context) =>
            {
                context.Response.ContentType = "text/html";
                await context.Response.SendFileAsync(Path.Combine(env.WebRootPath, "index.html"));
            });
        }
示例#11
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,
            IServiceProvider serviceProvider)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();
            loggerFactory.AddContext(LogLevel.Information, Configuration.GetConnectionString("MentorsAcademyLogDatabase"));

            CreateRoles(serviceProvider).Wait();

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

            app.UseStaticFiles();

            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
示例#12
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app,
                              IWebHostEnvironment env, IServiceProvider serviceProvider,
                              ILoggerFactory loggerFactory)
        {
            // Aqui vou trabalhar com logger, mas enviando os log para meu Banco
            loggerFactory.AddContext(LogLevel.Information, _config.GetConnectionString("StringConexaoBancoGestao"));
            loggerFactory.AddContext(LogLevel.Error, _config.GetConnectionString("StringConexaoBancoGestao"));
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/error");
                // Abordagens para tratar erro:
                //app.UseStatusCodePages();
                //app.UseStatusCodePages("text/html", "<h1> Status Code Page </h1>");
                //app.UseStatusCodePagesWithRedirects("MinhaPaginaErro/{0}");
                //app.UseStatusCodePagesWithReExecute("MinhaPaginaErro/{0}");
            }
            app.UseStaticFiles();
            app.UseSession();
            //app.UseNodeModules();
            app.UseRouting();
            app.UseAuthentication();
            app.UseAuthorization();
            app.UseEndpoints(cfg =>
            {
                cfg.MapRazorPages(); //Preciso disso porque o Identity vai usar Razor Pages
                cfg.MapAreaControllerRoute(
                    name: "areaAdministrativa",
                    areaName: "Admin",
                    pattern: "Admin/{controller=Admin}/{action=Index}/{id?}"
                    );
                cfg.MapControllerRoute(
                    name: "funcionarioPorCarreira",
                    pattern: "FuncionarioCarreira/{porCarreira}",
                    defaults: new { Controller = "FuncionarioCarreira", Action = "Index" }
                    );



                cfg.MapControllerRoute("Default", "{controller}/{action}/{id?}", new { controller = "App", Action = "Index" });
            });
            CreateRoles(serviceProvider).Wait();
        }
示例#13
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            loggerFactory.AddContext(LogLevel.Information, Configuration.GetConnectionString("DefaultConnection"));

            app.UseMvc();
        }
示例#14
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,
            UserManager <Usuario> userManager,
            RoleManager <Perfil> roleManager,
            EFApplicationContext context)
        {
            //StartScheduler();
            app.UseCors("CorsPolicy");

            //if (env.IsDevelopment())
            //{
            //    app.UseDeveloperExceptionPage();
            //}
            //else
            //{
            //    app.UseHsts();
            //}

            app.UseResponseCompression();
            app.UseMvc();

            var swaggerSettings = Configuration.GetSection("Swagger").Get <SwaggerSettings>();

            loggerFactory.AddContext(LogLevel.Warning, Configuration.GetConnectionString("DefaultConnection"));

#if DEBUG
            // Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger();
            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
            // specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", swaggerSettings.Title);
                c.RoutePrefix   = string.Empty;
                c.DocumentTitle = swaggerSettings.Title;
            });
#endif

            app.UseDefaultFiles();
            app.UseStaticFiles();
            // for Linux compatibility
            app.UseForwardedHeaders(new ForwardedHeadersOptions
            {
                ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
            });

            app.UseAuthentication();
            app.UseResponseCompression();
            app.UseCors("CorsPolicy");

            DbInitializer.Initialize(userManager, roleManager, context);
        }
示例#15
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)
        {
            using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                var context = serviceScope.ServiceProvider.GetService <ForumContext>();

                if (env.IsDevelopment())
                {
                    context.Database.Migrate();
                }
                var roleManager        = serviceScope.ServiceProvider.GetService <RoleManager <IdentityRole> >();
                var userManager        = serviceScope.ServiceProvider.GetService <UserManager <User> >();
                var accountService     = serviceScope.ServiceProvider.GetService <IAccountService>();
                var logger             = serviceScope.ServiceProvider.GetService <ILogger <IDatabaseInitializer> >();
                var userRepository     = serviceScope.ServiceProvider.GetService <IRepository <User> >();
                var categoryRepository = serviceScope.ServiceProvider.GetService <IRepository <Category> >();
                var postRepository     = serviceScope.ServiceProvider.GetService <IRepository <Post> >();

                new DatabaseInitializer().Seed(roleManager, userManager, Configuration, accountService, logger, userRepository, categoryRepository, postRepository).Wait();
            }

            loggerFactory.AddContext(app, LogLevel.Warning);

            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();
            }

            if (env.IsDevelopment() || env.EnvironmentName == "Testing")
            {
                app.UseFakeRemoteIpAddressMiddleware();
            }

            app.UseCors(builder => builder
                        .AllowAnyMethod()
                        .AllowAnyHeader()
                        .AllowCredentials()
                        .WithOrigins("http://localhost:4200"));

            app.UseRequestMiddleware();

            app.UseHttpsRedirection();

            app.UseSignalR(routes =>
            {
                routes.MapHub <NotifyHub>("/api/notify");
            });
            app.UseMvc();
        }
示例#16
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();
            loggerFactory.AddContext(LogLevel.Information, Configuration.GetConnectionString("MainDbContext"));

            // Configuring session handler for project.
            app.UseSession();

            app.UseMvc();
        }
示例#17
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.AddContext(LogLevel.Information, Configuration.GetConnectionString("LoggerDatabase"));

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());

            app.UseMvc();
        }
示例#18
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();
            loggerFactory.AddContext(LogLevel.Information, Configuration.GetConnectionString("LoggerDatabase"));

            app.UseExceptionHandler(env);

            app.UseCoreAppStaticFiles(enableCache: true);

            app.UseCoreAppMvc();

            app.UseCoreAppDirectoryBrowser();

            app.UseAuthentication();
        }
示例#19
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            loggerFactory.AddContext(LogLevel.Error, app);

            app.Use(async(ctx, next) =>
            {
                await next();
                if (ctx.Response.StatusCode == 204)
                {
                    ctx.Response.ContentLength = 0;
                }
            });

            app.UseCors(x => x
                        .AllowAnyMethod()
                        .AllowAnyHeader()
                        .AllowCredentials()
                        .WithOrigins("http://localhost:4200"));

            app.UseSeedAdminMiddleware();
            app.UseSeedCategoriesMiddleware();
            app.UseSeedIngredientsMiddleware();
            app.UseSeedProductsMiddleware();

            app.UseSignalR(routes =>
            {
                routes.MapHub <ProductsHub>("/api/notify");
            });

            app.UseHttpsRedirection();
            app.UseAuthentication();
            app.UseMvc();
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "PizzaLab API V1");
            });
        }
示例#20
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();
            loggerFactory.AddContext(LogLevel.Information, Configuration.GetConnectionString("MainDbContext"));

            app.UseSession();

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Login}/{id?}");
            });
        }
示例#21
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();
            loggerFactory.AddContext(LogLevel.Information, Configuration.GetConnectionString("DefaultConnection"));

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseDefaultFiles();
            app.UseStaticFiles();

            app.UseAuthentication();

            app.UseMvc();
        }
示例#22
0
        /// <summary>
        /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        /// </summary>
        /// <param name="app"></param>
        /// <param name="env"></param>
        /// <param name="loggerFactory"></param>
        //============================================================
        //Revision History
        //Date        Author          Description
        //06/28/2017  TB               Created
        //06/30/2017  AA               Updated to handle Auth0 authentication with jwt
        //============================================================
        public virtual void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            //configure linq2db
            DataConnection.DefaultDataProvider = Configuration.GetSection("DBSettings").GetValue <string>("Provider");
            DataConnection.AddConfiguration("default", Configuration.GetSection("DBSettings").GetValue <string>("ConnectionString"), null);

            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddContext(LogLevel.Warning, Configuration.GetSection("DBSettings").GetValue <string>("ConnectionString"));

            if (env.IsDevelopment())
            {
                loggerFactory.AddDebug();
            }



            app.UseAuthentication();
            app.UseMiddleware <MaintenanceMode>();
            app.UseResponseCompression();
            app.UseMvc();
            app.UsePathBase(Configuration.GetSection("Urls").GetValue <string>("Base"));
            app.UseStaticFiles();
            app.UseDefaultFiles(new DefaultFilesOptions()
            {
                DefaultFileNames = new[] { "index.html" }
            });

            //override mapping to keep .net core from interferring with angular routing
            app.MapWhen(context =>
            {
                var path = context.Request.Path.Value.ToLower();
                return(path.Contains("/") && !path.Contains(".js") && !path.Contains("/api/") &&
                       !path.Contains(".ico"));
            },
                        branch =>
            {
                branch.Use((context, next) =>
                {
                    context.Request.Path = new PathString("/index.html");
                    return(next());
                });

                branch.UseStaticFiles();
            });
        }
示例#23
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()
            //    .AddDebug();

            //loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddContext(LogLevel.Information, Configuration.GetConnectionString("LoggerDatabase"));

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseMvc();
        }
示例#24
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, PLSODb context, IServiceScopeFactory scopeFactory, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));                             // https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging
            loggerFactory.AddDebug();
            loggerFactory.AddContext(LogLevel.Warning, Configuration.GetConnectionString("PLSOData")); // Should just save Warning, Error and Critical messages to the Database

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

            app.UseStaticFiles();
            app.UseAuthentication();

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

            // So we can create instances of DI items when you can not inject them naturally
            ServiceInstantiator.Instance = app.ApplicationServices;

            // Enable automatic migrations
            try {
                using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope()) {
                    serviceScope.ServiceProvider.GetService <PLSODb>().Database.EnsureCreated();
                    serviceScope.ServiceProvider.GetService <PLSODb>().Database.Migrate();
                }
            } catch (Exception e) {
                logger.LogError(e, "Startup Migration Error");
            }
        }
示例#25
0

        
示例#26
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)
        {
            app.UseStaticFiles();

            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();
            loggerFactory.AddContext(LogLevel.Error, Configuration.GetConnectionString(SqlConstant.DatabaseConnectionName.LoggerDatabaseConnectionName));

            app.UseExceptionHandler(env);

            //app.UseCoreAppStaticFiles(enableCache: true);

            // Note: The position is very important. it must always above UseMvc.
            app.UseAuthentication();
            //app.UseSignalR((options) =>
            //{
            //    options.MapHub<ChangeProxyHub>("/hubs/changeproxy");
            //});

            app.UseCors(options => options.AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader());



            // Swagger ui
            app.UseCoreAppSwagger();

            // Mvc
            //app.UseHttpsRedirection();
            app.UseSession();
            app.UseCoreAppMvc();
            app.UseCoreAppDirectoryBrowser();


            // Single page.
            //app.UseCoreAppSPA(env);
        }
示例#27
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)
        {
            var connection = @"Data Source=ADMIN-PC;Initial Catalog=AngularASPCoreDemo;Integrated Security=True";

            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();
            loggerFactory.AddContext(LogLevel.Information, connection);

            app.UseAuthentication();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
                {
                    HotModuleReplacement = true
                });
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

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

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

        
示例#29
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)
        {
            #region 1. Read Connection String and configure LOggerFactory
            var connection = Configuration.GetConnectionString("DefaultConnection") ?? throw new ArgumentNullException("Configuration.GetConnectionString(\"DefaultConnection\")");

            // loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            // loggerFactory.AddDebug();
            loggerFactory.AddContext(LogLevel.Error, connection);
            #endregion

            #region 2 Exception Logging
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler();
            }
            #endregion

            //Extension method to load all required middleweare
            app.UseAllRequiredServices();
        }
示例#30
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IParameterService parameterService)
        {
            var appSettings = Configuration.GetSection("AppSettings");

            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

            //loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            //loggerFactory.AddDebug();
            loggerFactory.AddContext(LogLevel.Information, app.ApplicationServices.GetService <IHttpContextAccessor>());

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Admmin/DashBoard/Index");
            }

            AppContext.Configure(app.ApplicationServices.
                                 GetRequiredService <IHttpContextAccessor>(), appSettings
                                 );

            //app.UseCookieAuthentication(new CookieAuthenticationOptions
            //{
            //    AuthenticationScheme = "Cookies",
            //    DataProtectionProvider = DataProtectionProvider.Create(new DirectoryInfo(Environment.ContentRootPath + "\\temp-keys")),
            //});
            app.UseAuthentication();
            app.UseStaticFiles();
            app.UseResponseCaching();
            app.UseSession();
            app.UseCors(builder => builder
                        .AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader()
                        .AllowCredentials());
            #region MutiLanguage
            //var supportedCultures = new[]
            //        {
            //            new CultureInfo(enUSCulture),
            //            new CultureInfo(viVNCulture),
            //            new CultureInfo("en-AU"),
            //            new CultureInfo("en-GB"),
            //            new CultureInfo("en"),
            //            new CultureInfo("es-ES"),
            //            new CultureInfo("es-MX"),
            //            new CultureInfo("es"),
            //            new CultureInfo("fr-FR"),
            //            new CultureInfo("fr"),
            //        };

            //app.UseRequestLocalization(new RequestLocalizationOptions
            //{
            //    DefaultRequestCulture = new RequestCulture(enUSCulture),
            //    // Formatting numbers, dates, etc.
            //    SupportedCultures = supportedCultures,
            //    // UI strings that we have localized.
            //    SupportedUICultures = supportedCultures
            //});

            app.UseStaticFiles();
            // To configure external authentication,
            // see: http://go.microsoft.com/fwlink/?LinkID=532715
            //app.UseAuthentication();
            //app.UseMvcWithDefaultRoute();
            #endregion
            //app.UseRequestLocalization();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=CalendarRegistration}/{action=Index}");
                routes.MapRoute(
                    name: "admin",
                    template: "{area:exists}/{controller=DashBoard}/{action=Index}/{id?}");
                routes.MapRoute(
                    name: "angular",
                    template: "{*url}",
                    defaults: new { controller = "CalendarRegistration", action = "Index" });
            });
        }