// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IWebHostEnvironment 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.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); // Using pre .Net Core 3.0 MVC routing instead of Endpoint routing (.Net core >= 3.0) // https://github.com/dotnet/aspnetcore/issues/9542 // https://devblogs.microsoft.com/aspnet/asp-net-core-updates-in-net-core-3-0-preview-4/ app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env) { app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "Bizanc Ominichain API V1.0.0"); c.DocumentTitle = "Bizanc Ominichain Network"; c.RoutePrefix = "api-docs"; }); app.UseCors(builder => { builder.AllowAnyOrigin(); builder.AllowAnyHeader(); builder.AllowAnyMethod(); }); //app.UseMvc(); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseDashboardSamples(); #if netcoreapp3 app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); #else app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); #endif }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env) { if (env.EnvironmentName == "Development") { app.UseDeveloperExceptionPage(); } app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); c.RoutePrefix = string.Empty; }); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); // global cors policy app.UseCors(x => x .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader()); app.UseEndpoints(endpoints => { // endpoints.MapRazorPages(); endpoints.MapControllers(); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseHttpsRedirection(); app.UseStaticFiles(); //app.UseAuthentication(); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapDefaultControllerRoute(); }); //app.UseMvc(); }
public Startup(Microsoft.AspNetCore.Hosting.IWebHostEnvironment env) { Configuration = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json") .Build(); }
private static void UseLuceneSearch(IWebHostEnvironment env, IHangfireBackJob hangfire, LuceneIndexerOptions luceneIndexerOptions) { Task.Run(() => { Console.WriteLine("正在导入自定义词库..."); double time = HiPerfTimer.Execute(() => { var lines = File.ReadAllLines(Path.Combine(env.ContentRootPath, "App_Data", "CustomKeywords.txt")); var segmenter = new JiebaSegmenter(); foreach (var word in lines) { segmenter.AddWord(word); } }); Console.WriteLine($"导入自定义词库完成,耗时{time}s"); }); string lucenePath = Path.Combine(env.ContentRootPath, luceneIndexerOptions.Path); if (!Directory.Exists(lucenePath) || Directory.GetFiles(lucenePath).Length < 1) { Console.WriteLine("索引库不存在,开始自动创建Lucene索引库..."); hangfire.CreateLuceneIndex(); Console.WriteLine("索引库创建完成!"); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); //app.UseCookiePolicy(); // not in Core 3.1 app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); //Core 3.1 app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapRazorPages(); }); }
//private readonly IAuthorizationService _authorizationService; public TeachersController(/*IAuthorizationService authorizationService,*/ AspProektContext context, IWebHostEnvironment e, IWebHostEnvironment hostEnvironment) { //_authorizationService = authorizationService; he = e; _context = context; this.hostEnvironment = hostEnvironment; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public static void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseMvc(routes => { routes.MapRoute( name: "DecryptRoute", template: "{keyName}/{keyId}/Decrypt", defaults: new { controller = "Keys", action = "Decrypt" }); routes.MapRoute( name: "GetKeyRoute", template: "{keyName}", defaults: new { controller = "Keys", action = "GetKey" }); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } // 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.UseHttpsRedirection(); app.UseMvc(); //app.UseEndpoints(endpoints => //{ // endpoints.MapControllers(); //}); }
public void Configure_tmp(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env, ILogger <Startup> logger) { //If you run the project using the .NET Core CLI, you can see the logged information on the Console window //If you run the project directly from Visual Studio, you can see the logged information in the output window. //Select ASP.NET Core Web Server from the dropdownlist in the output window. app.Use(async(context, next) => { logger.LogInformation("MW1: Incoming Request"); await next(); //go to the next middleware until it finishes logger.LogInformation("MW1: Outgoing Response"); }); app.Use(async(context, next) => { logger.LogInformation("MW2: Incoming Request"); await next(); //go to the next middleware until it finishes logger.LogInformation("MW2: Outgoing Response"); }); app.Run(async(context) => { await context.Response.WriteAsync("MW3: Request handled and response produced"); logger.LogInformation("MW3: Request handled and response produced"); }); }
public AssetBundleTagHelper(IUrlHelperFactory urlHelperFactory, IHostEnvironmentType hostingEnvironment, AssetBundleOptions options, IFileVersionProvider fileVersionProvider) { this.hostingEnvironment = hostingEnvironment; this.urlHelperFactory = urlHelperFactory; this.options = options; this.fileVersionProvider = fileVersionProvider; }
public ReDocMiddleware( RequestDelegate next, IHostingEnvironment hostingEnv, ILoggerFactory loggerFactory, IOptions <ReDocOptions> optionsAccessor) : this(next, hostingEnv, loggerFactory, optionsAccessor.Value) { }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env) { InitializeIdentityServerData(app); app.UseIdentityServer(); app.UseStaticFiles(); app.UseMvcWithDefaultRoute(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env) { if (string.Equals(env.EnvironmentName, "Development")) { app.UseDeveloperExceptionPage(); } app.UseMvc(); }
#pragma warning disable CA1822 // Member Configure does not access instance data and can be marked as static public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env) #pragma warning restore CA1922 { if (!env.IsDevelopment()) { app.UseHsts(); } app.UseHttpsRedirection() .UseStaticFiles() .UseCookiePolicy() .UseSession() .UseAuthentication() .UseMiddleware <Services.SessionRestore>() .UseMvc(routes => { routes.MapRoute( name: "Guid parameter", template: "{controller}/{action}/{guid}", defaults: new { controller = "Home", action = "Index" }, constraints: new { guid = new GuidRouteConstraint() }); routes.MapRoute( name: "Only action", template: "{controller=Home}/{action=Index}"); }); app.UseExceptionHandler(errorApp => { errorApp.Run(async context => { context.Response.StatusCode = 500; context.Response.ContentType = "text/html"; StringBuilder rsBody = new StringBuilder(2048); rsBody.Append("<html lang=\"ru\"><body>\r\n") .Append("Something unexpected bla-bla-bla happened... Please try refreshing the page.<br><br>\r\n"); var exceptionHandlerPathFeature = context.Features.Get <IExceptionHandlerPathFeature>(); Exception unhandledExc = exceptionHandlerPathFeature.Error; if (unhandledExc != null) { if (env.IsDevelopment()) { rsBody.Append("</br>") .Append("Unhandled exception: " + unhandledExc.ToString()); } logger.LogError(unhandledExc, "Unhandled exception while accessing resource {0}:", context.Request.Path); } rsBody.Append("<a href=\"/\">Home</a><br>\r\n") .Append("</body></html>\r\n"); await context.Response.WriteAsync(rsBody.ToString()).ConfigureAwait(false); }); }); }
public ConfigureSwaggerGeneratorOptions( IOptions <SwaggerGenOptions> swaggerGenOptionsAccessor, IServiceProvider serviceProvider, IHostingEnvironment hostingEnvironment) { _swaggerGenOptions = swaggerGenOptionsAccessor.Value; _serviceProvider = serviceProvider; _hostingEnvironment = hostingEnvironment; }
/// <summary> /// Configure /// </summary> /// <param name="app"></param> /// <param name="env"></param> /// <param name="db"></param> /// <param name="hangfire"></param> /// <param name="luceneIndexerOptions"></param> public void Configure(IApplicationBuilder app, IWebHostEnvironment env, DataContext db, IHangfireBackJob hangfire, LuceneIndexerOptions luceneIndexerOptions) { ServiceProvider = app.ApplicationServices; if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } //db.Database.Migrate(); var dic = db.SystemSetting.ToDictionary(s => s.Name, s => s.Value); //初始化系统设置参数 foreach (var(key, value) in dic) { CommonHelper.SystemSettings.TryAdd(key, value); } UseLuceneSearch(env, hangfire, luceneIndexerOptions); if (bool.Parse(Configuration["Https:Enabled"])) { app.UseHttpsRedirection().UseRewriter(new RewriteOptions().AddRedirectToNonWww()); // URL重写 } app.UseSession().UseCookiePolicy(); //注入Session app.UseRequestIntercept(); //启用网站请求拦截 app.UseStaticHttpContext(); //注入静态HttpContext对象 app.UseStaticFiles(new StaticFileOptions //静态资源缓存策略 { OnPrepareResponse = context => { context.Context.Response.Headers[HeaderNames.CacheControl] = "public,no-cache"; context.Context.Response.Headers[HeaderNames.Expires] = DateTime.UtcNow.AddDays(7).ToString("R"); }, ContentTypeProvider = new FileExtensionContentTypeProvider(MimeMapper.MimeTypes), }); app.UseHangfireServer().UseHangfireDashboard("/taskcenter", new DashboardOptions() { Authorization = new[] { new MyRestrictiveAuthorizationFilter() } }); //配置hangfire app.UseCors(builder => builder.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin()); //配置跨域 app.UseResponseCaching().UseResponseCompression(); //启动Response缓存 app.UseRouting(); // 放在 UseStaticFiles 之后 app.UseEndpoints(endpoints => { endpoints.MapControllers(); // 属性路由 endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}"); // 默认路由 endpoints.MapHub <MyHub>("/hubs"); }); HangfireJobInit.Start(); //初始化定时任务 }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { _serverAddressesFeature = app.ServerFeatures.Get <IServerAddressesFeature>(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Demo/Error"); } app.UseResponseCompression(); app.UseStaticFiles(); // app.UseCookiePolicy(); app.UseResponseCaching(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); /* * app.Use((context, next) => * { * var endpointFeature = context.Features[typeof(IEndpointFeature)] as IEndpointFeature; * var endpoint = endpointFeature?.Endpoint; * * if (endpoint != null) * { * var metadataCollection = endpoint?.Metadata; * var pattern = (endpoint as RouteEndpoint)?.RoutePattern?.RawText; * * Console.WriteLine("Name: " + endpoint.DisplayName); * Console.WriteLine($"Route Pattern: {pattern}"); * Console.WriteLine("Metadata Types: " + string.Join(", ", metadataCollection)); * } * return next(); * }); */ app.UseEndpoints(route => { route.MapHub <QuotesHub>("/quotes"); route.MapControllerRoute( name: "default", pattern: "{controller=Demo}/{action=Index}/{id?}", defaults: new { controller = "Demo", action = "Index" } ); }); }
public SwaggerUIMiddleware( RequestDelegate next, IHostingEnvironment hostingEnv, ILoggerFactory loggerFactory, SwaggerUIOptions options) { _options = options ?? new SwaggerUIOptions(); _staticFileMiddleware = CreateStaticFileMiddleware(next, hostingEnv, loggerFactory, options); _swaggerUIIndexHtmlBuilder = new SwaggerUIIndexHtmlBuilder(_options); }
public Startup(Microsoft.AspNetCore.Hosting.IWebHostEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) .AddEnvironmentVariables(); Configuration = builder.Build(); }
public ReDocMiddleware( RequestDelegate next, IHostingEnvironment hostingEnv, ILoggerFactory loggerFactory, ReDocOptions options) { _options = options ?? new ReDocOptions(); _jsonSerializer = CreateJsonSerializer(); _staticFileMiddleware = CreateStaticFileMiddleware(next, hostingEnv, loggerFactory, options); }
public Startup(Microsoft.AspNetCore.Hosting.IWebHostEnvironment evm) { var builder = new ConfigurationBuilder() .SetBasePath(evm.ContentRootPath) .AddJsonFile("appsettings.json", true, true) .AddJsonFile($"appsettings.{evm.EnvironmentName}.json", true) .AddEnvironmentVariables(); Configuration = builder.Build(); AppSettings.Instance.SetConfiguration(Configuration); }
private StaticFileMiddleware CreateStaticFileMiddleware(RequestDelegate next, IHostingEnvironment hostingEnv, ILoggerFactory loggerFactory) { var staticFileOptions = new StaticFileOptions { RequestPath = string.IsNullOrEmpty(_options.RoutePrefix) ? string.Empty : _options.RoutePrefix, FileProvider = new EmbeddedFileProvider(typeof(HttpReportsDashboardUIMiddleware).Assembly, EmbeddedFileNamespace), }; return(new StaticFileMiddleware(next, hostingEnv, Options.Create(staticFileOptions), loggerFactory)); }
public Startup(IHostingEnvironment env) { _env = env; var builder = new ConfigurationBuilder() .SetBasePath(_env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables(); _config = builder.Build(); }
public Startup(Microsoft.AspNetCore.Hosting.IWebHostEnvironment env) { var builder = new Microsoft.Extensions.Configuration.ConfigurationBuilder(); builder.SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json") //add configuration.json .AddJsonFile("configuration.json", optional: false, reloadOnChange: true) .AddEnvironmentVariables(); Configuration = builder.Build(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env) { if (env.IsDevelopment()) { GlobalContext.SystemConfig.Debug = true; app.UseDeveloperExceptionPage(); } else { app.UseDeveloperExceptionPage(); } string resource = Path.Combine(env.ContentRootPath, "Resource"); FileHelper.CreateDirectory(resource); app.UseStaticFiles(new StaticFileOptions { OnPrepareResponse = GlobalContext.SetCacheControl }); app.UseStaticFiles(new StaticFileOptions { RequestPath = "/Resource", FileProvider = new PhysicalFileProvider(resource), OnPrepareResponse = GlobalContext.SetCacheControl }); app.UseMiddleware(typeof(GlobalExceptionMiddleware)); app.UseCors(builder => { builder.WithOrigins(GlobalContext.SystemConfig.AllowCorsSite.Split(',')).AllowAnyHeader().AllowAnyMethod().AllowCredentials(); }); app.UseSwagger(c => { c.RouteTemplate = "api-doc/{documentName}/swagger.json"; }); app.UseSwaggerUI(c => { c.RoutePrefix = "api-doc"; c.SwaggerEndpoint("v1/swagger.json", "TestCenter Api v1"); }); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute("default", "{controller=ApiHome}/{action=Index}/{id?}"); }); GlobalContext.ServiceProvider = app.ApplicationServices; if (!GlobalContext.SystemConfig.Debug) { new JobCenter().Start(); // 定时任务 } }
public HttpReportsDashboardUIMiddleware(RequestDelegate next, IOptions <DashboardUIOptions> options, IHostingEnvironment hostingEnv, ILoggerFactory loggerFactory) { _options = options?.Value ?? throw new ArgumentNullException(nameof(options)); _staticFileMiddleware = CreateStaticFileMiddleware(next, hostingEnv, loggerFactory); _serializerSettings = new JsonSerializerSettings() { ContractResolver = new CamelCasePropertyNamesContractResolver(), }; }
public Startup(Microsoft.AspNetCore.Hosting.IWebHostEnvironment env, ILogger <Startup> logger) { Contract.Assert(env != null); var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) .AddEnvironmentVariables() .AddUserSecrets <Startup>(); Configuration = builder.Build(); this.logger = logger; }