예제 #1
0
        public void ConfigureAppConfiguration(WebHostBuilderContext context, IConfigurationBuilder configurationBuilder)
        {
            if (hostingEnvironment.IsDevelopment())
            {
                configurationBuilder.SetBasePath(Directory.GetCurrentDirectory());
                //  configurationBuilder.SetBasePath(Path.Combine(Directory.GetCurrentDirectory(), "../../.."));
            }

            configurationBuilder

            .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
            .AddJsonFile($"appsettings.{context.HostingEnvironment.EnvironmentName}.json", optional: true);
        }
        /// <summary>
        /// 摘要:
        ///     在执行操作方法后由 ASP.NET MVC 框架调用。
        ///
        ///     执行完Action方法之后调用此方法,如果报错的话,可以在这一步处理
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            #region 如果Action执行之后发现报错了
            if (filterContext.Exception != null)
            {
                if (_env.IsDevelopment())
                {
                    //如果是测试环境的话,那么啥都不做,直接显示报错页面
                }
                else  //由于中间件已经给我定义好了报错的页面了,所以这里只需要对Api报错进行处理就好了
                {
                    var path = filterContext.HttpContext.Request.Path.ToString();
                    if (path.Contains("/api", StringComparison.OrdinalIgnoreCase))
                    {
                        filterContext.Canceled = true;
                        filterContext.Result   = new JsonResult(new JsonResultObj {
                            code = 999,
                            msg  = Common.Constant.ERROR_DEFAULT
                        });
                    }
                }
            }
            #endregion

            base.OnActionExecuted(filterContext);
        }
예제 #3
0
        private static X509Certificate2 LoadCertificate(EndpointConfiguration config, Microsoft.Extensions.Hosting.IHostingEnvironment environment)
        {
            if (config.StoreName != null && config.StoreLocation != null)
            {
                using (var store = new X509Store(config.StoreName, Enum.Parse <StoreLocation>(config.StoreLocation)))
                {
                    store.Open(OpenFlags.ReadOnly);
                    var certificate = store.Certificates.Find(
                        X509FindType.FindBySubjectName,
                        config.Host,
                        validOnly: !environment.IsDevelopment());

                    if (certificate.Count == 0)
                    {
                        throw new InvalidOperationException($"Certificate not found for {config.Host}.");
                    }

                    return(certificate[0]);
                }
            }

            if (config.FilePath != null && config.Password != null)
            {
                return(new X509Certificate2(config.FilePath, config.Password));
            }

            throw new InvalidOperationException("No valid certificate configuration found for the current endpoint.");
        }
예제 #4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, Microsoft.Extensions.Hosting.IHostingEnvironment env, IConfiguration config)
        {
            // Cheer 100 Crazy240sx 12/18/2018

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

            app.UseHsts();
            app.UseHttpsRedirection();

            app.UseStaticFiles();

            app.UseSignalR(configure =>
            {
                configure.MapHub <FollowerHub>("/followerstream");
                configure.MapHub <GithubyMcGithubFace>("/github");
                configure.MapHub <AttentionHub>("/attentionhub");
            });

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
예제 #5
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory,
                              IAmqpService amqpService, IApplicationLifetime applicationLifetime)
        {
            if (_hostingEnvironment.IsDevelopment() || _hostingEnvironment.IsEnvironment("DevelopmentServer"))
            {
                app.UseDeveloperExceptionPage();
            }

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

            //loggerFactory.AddDebug();
            loggerFactory.AddLog4Net(Path.Combine(ContentRoot, "config/log4net.config"));

            app.UseMvc();
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "SmartDevicesGatewayAPI");
            });

            //using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope())
            //{
            //    var dbContext = serviceScope.ServiceProvider.GetService<SmartdevicesGatewayDBContext>();

            //    var dbNewlyCreated = dbContext.Database.EnsureCreated();
            //}

            applicationLifetime.ApplicationStarted.Register(OnStarted);
            applicationLifetime.ApplicationStopping.Register(OnShutdown);

            _app = app;
        }
예제 #6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IBackgroundJobClient backgroundJobs, IHostingEnvironment env, IRecurringJobManager recurringJobManager, IServiceProvider serviceProvider)
        // public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/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.UseHangfireDashboard();
            app.UseStaticFiles();
            app.UseHangfireServer();
            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapRazorPages();
                endpoints.MapHangfireDashboard();
            });
            SetupJobs();
        }
예제 #7
0
파일: Startup.cs 프로젝트: matand/bankor
        // 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();
            }

            // 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");
            });


            app.UseRouting();
            app.UseCors("all");

            app.UseEndpoints(endpoints => {
                endpoints.MapControllers();
            });
        }
예제 #8
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            using (var scope = app.ApplicationServices.CreateScope())
                using (var sampleDbContext = scope.ServiceProvider.GetService <SampleDbContext>())
                {
                    sampleDbContext.Database.EnsureCreated();
                }

#if NETCOREAPP2_1
            app.UseMvcWithDefaultRoute();
#else
            app.UseRouting();

            app.UseEndpoints(endpoint =>
            {
                endpoint.MapDefaultControllerRoute();
                endpoint.MapGrpcService <GreeterImpl>();
            });
#endif
        }
예제 #9
0
 private static bool CheckHostingEnvironmentIsProductionOrStagingOrDevelopment(
     Microsoft.Extensions.Hosting.IHostingEnvironment hostingEnvironment)
 {
     return(hostingEnvironment.IsProduction() ||
            hostingEnvironment.IsStaging() ||
            hostingEnvironment.IsDevelopment());
 }
예제 #10
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
            {
                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();
            }
            loggerFactory.AddSerilog();
            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });
        }
예제 #11
0
        public void Configure(IApplicationBuilder app, Microsoft.Extensions.Hosting.IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
                {
                    HotModuleReplacement      = true,
                    ReactHotModuleReplacement = true
                });
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();
            app.UseMetricServer();

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

                routes.MapSpaFallbackRoute(
                    name: "spa-fallback",
                    defaults: new { controller = "Home", action = "Index" });
            });
        }
예제 #12
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, Microsoft.Extensions.Hosting.IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

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

            app.UseAuthentication();
            //app.Run();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
예제 #13
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, Microsoft.Extensions.Hosting.IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseCors("ElektronskaOglasnaTabla");
            app.UseStaticFiles();
            app.UseStaticFiles(new StaticFileOptions()
            {
                FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"Resources")),
                RequestPath  = new PathString("/Resources")
            });

            app.UseSignalR(options =>
            {
                options.MapHub <AnnouncementHub>("/AnnouncementHub");
                options.MapHub <MessageHub>("/MessageHub");
            });

            //app.UseCookiePolicy();
            app.UseAuthentication();

            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, Microsoft.Extensions.Hosting.IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Error");
            }

            app.UseStaticFiles();

            app.UseSignalR(configure =>
            {
                configure.MapHub <FollowerHub>("/followerstream");
            });

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
예제 #15
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, Microsoft.Extensions.Hosting.IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler(builder => {
                    builder.Run(async context => {
                        context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;

                        var error = context.Features.Get <IExceptionHandlerFeature>();
                        if (error != null)
                        {
                            context.Response.AddApplicationError(error.Error.Message);
                            await context.Response.WriteAsync(error.Error.Message);
                        }
                    });
                });
                // 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.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
            app.UseAuthentication();
            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)
        {
            var hub = app.ApplicationServices.GetService <IHubContext <LogHub> >();

            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .WriteTo.SignalRLogger <LogHub>(hub)
                         .WriteTo.Console()
                         .CreateLogger();

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

            app.UseSignalR(config =>
            {
                config.MapHub <ChatHub>("/chat");
                config.MapHub <LogHub>("/log");
            });

            app.Use(async(context, next) =>
            {
                await context.Response.WriteAsync("Hello World!");

                await next();
            });

            // app.Run(async context =>
            // {
            //     await context.Response.WriteAsync("Hello World!");
            // });
        }
예제 #17
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, Microsoft.Extensions.Hosting.IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseMvc();
        }
예제 #18
0
        /// <summary>
        /// The uri to the server that implements the ACME protocol for certificate generation.
        /// </summary>
        internal static Uri GetAcmeServer(LetsEncryptOptions options, IHostEnvironment env)
        {
            var useStaging = options.UseStagingServerExplicitlySet
                ? options.UseStagingServer
                : env.IsDevelopment();

            return(useStaging
                ? WellKnownServers.LetsEncryptStagingV2
                : WellKnownServers.LetsEncryptV2);
        }
예제 #19
0
        public void Configure(IApplicationBuilder app, Microsoft.Extensions.Hosting.IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseStaticFiles();
            app.UseOwin(x => x.UseNancy());
        }
예제 #20
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        //Microsoft.Extensions.Hosting
        public void Configure(IApplicationBuilder app, Microsoft.Extensions.Hosting.IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/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.UseStaticFiles();
            if (!env.IsDevelopment())
            {
                app.UseSpaStaticFiles();
            }

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{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");
                }
            });
        }
예제 #21
0
    public Task <IEnumerable <X509Certificate2> > GetCertificatesAsync(CancellationToken cancellationToken)
    {
        if (!_environment.IsDevelopment())
        {
            return(Task.FromResult(Enumerable.Empty <X509Certificate2>()));
        }

        var certs = FindDeveloperCert();

        return(Task.FromResult(certs));
    }
예제 #22
0
        public Task StartAsync(CancellationToken cancellationToken)
        {
            if (!_environment.IsDevelopment())
            {
                return(Task.CompletedTask);
            }

            FindDeveloperCert();

            return(Task.CompletedTask);
        }
예제 #23
0
        public void Configure(IApplicationBuilder app, Microsoft.Extensions.Hosting.IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseResponseCompression(); // Compression
            app.UseDefaultFiles();        // Serving index.html by default
            app.UseStaticFiles();         // Static files support
        }
예제 #24
0
        public void Configure(IApplicationBuilder app, Microsoft.Extensions.Hosting.IHostingEnvironment env, IMessageSender messageSender)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.Run(async (context) =>
            {
                await context.Response.WriteAsync(messageSender.Send());
            });
        }
예제 #25
0
        public void Configure(IApplicationBuilder app, Microsoft.Extensions.Hosting.IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/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.UseStaticFiles();

            app.UseSpaStaticFiles();

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

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

            app.UseSpa(spa =>
            {
                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseAngularCliServer(npmScript: "start");
                }
            });
        }
예제 #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)
        {
            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.UseMvcWithDefaultRoute();
        }
예제 #27
0
        public Startup(Microsoft.Extensions.Hosting.IHostingEnvironment hostEnvironment)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(hostEnvironment.ContentRootPath)
                          .AddJsonFile("appsettings.json", true, true)
                          .AddJsonFile($"appsettings.{hostEnvironment.EnvironmentName}.json", true, true)
                          .AddEnvironmentVariables();

            if (hostEnvironment.IsDevelopment())
            {
            }

            Configuration = builder.Build();
        }
예제 #28
0
        public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(env.ContentRootPath)
                          .AddJsonFile("appsettings.json",
                                       optional: false,
                                       reloadOnChange: true)
                          .AddEnvironmentVariables();

            if (env.IsDevelopment())
            {
                builder.AddUserSecrets <Startup>();
            }
            Configuration = builder.Build();
        }
예제 #29
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, Microsoft.Extensions.Hosting.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();
        }
        /// <summary>
        /// Configure the environment.
        /// </summary>
        /// <param name="app">App builder.</param>
        /// <param name="env">env hosting.</param>
        /// <param name="telemetryClient">Application Insights.</param>
#pragma warning disable CA1822 // Mark members as static

        public void Configure(IApplicationBuilder app, Microsoft.Extensions.Hosting.IHostingEnvironment env, TelemetryClient telemetryClient)
#pragma warning restore CA1822 // Mark members as static
        {
            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.ConfigureExceptionHandler(telemetryClient);
            app.UseHttpsRedirection();
            app.UseMvc();
        }