public GetCore1(Tool.SqlCore.DbHelper dbHelper, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env, IHttpContextAccessor context) { this.dbHelper = dbHelper; }
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); }
public CandidateController(RejoinDbContext context, Microsoft.AspNetCore.Hosting.IWebHostEnvironment hosting, IAuth auth, IRelativeTime relativetime) : base(context) { _relativetime = relativetime; _auth = auth; _context = context; _hosting = hosting; }
/// <summary> /// Application configuration /// </summary> /// <param name="app"></param> public static void ConfigureApp(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env, IConfiguration configuration) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseHttpsRedirection(); app.UseRouting(); app.UseCors(policy); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); // 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", configuration["App:Name"]); }); }
// 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(); } app.UseSession(); //app.UseStaticFiles(); app.UseDefaultFiles(); app.UseStaticFiles(); app.UseRouting(); app.UseCors(builder => builder .WithOrigins("http://localhost") .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials() ); app.UseAuthentication(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
public void Configure (Microsoft.AspNetCore.Builder.IApplicationBuilder app, Microsoft.AspNetCore.Hosting.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.UseHttpsRedirection(); app.UseCors(policyName: AdminCorsPolicy); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
public static void UseExceptionHandlerApp(this IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env) { app.UseExceptionHandler(errorApp => { errorApp.Run(async context => { var exceptionHandlerPathFeature = context.Features.Get <IExceptionHandlerPathFeature>(); if (exceptionHandlerPathFeature?.Error != null) { if (exceptionHandlerPathFeature.Error is DominioException ex) { context.Response.StatusCode = (int)ex.HttpStatusCode; context.Response.ContentType = "application/json"; await context.Response.WriteAsync(JsonSerializer.Serialize(new { mensagem = ex.Message })); return; } if (env.IsDevelopment()) { context.Response.StatusCode = 500; context.Response.ContentType = "text/html"; await context.Response.WriteAsync(exceptionHandlerPathFeature.Error.ToString()); return; } } context.Response.StatusCode = 500; context.Response.ContentType = "text/html"; context.Response.ContentType = "Ocorreu um erro"; }); }); }
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("索引库创建完成!"); } }
public ProjectControllersTest() { _EmpregadosController = new PortalMVC.Controllers.EmpregadosController(); Microsoft.AspNetCore.Hosting.IWebHostEnvironment env = null; _FaturasController = new PortalMVC.Controllers.FaturasController(env); _ProdutosController = new PortalMVC.Controllers.ProdutosController(); }
public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseWebSockets(); // app.useSt(); // For the wwwroot folder //app.UseStaticFiles(new StaticFileOptions //{ // FileProvider = new PhysicalFileProvider( //"F:\\MyProject\\VRPWithZhangkun\\MainApp\\VRPWithZhangkun\\VRPServer\\WebApp\\webHtml"), // RequestPath = "/StaticFiles" //}); //app.Map("/postinfo", HandleMapdownload); var webSocketOptions = new WebSocketOptions() { KeepAliveInterval = TimeSpan.FromSeconds(3600 * 24), ReceiveBufferSize = webWsSize }; app.UseWebSockets(webSocketOptions); app.Map("/websocket", WebSocketF); // app.Map("/notify", notify); Console.WriteLine($"启动TCP连接!{ ConnectInfo.tcpServerPort}"); Thread th = new Thread(() => startTcp()); th.Start(); }
public WebCustomizeSession(Microsoft.JSInterop.IJSRuntime jsr , Microsoft.AspNetCore.Http.IHttpContextAccessor hca , Microsoft.AspNetCore.Hosting.IWebHostEnvironment whe) : base(jsr, hca) { _whe = whe; }
public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } //else //{ // app.UseExceptionHandler("/Home/Error"); // app.UseHsts(); //} app.UseHttpsRedirection(); app.UseRouting(); app.UseCors("Default"); app.UseAuthorization(); app.UseSwagger(); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "v1")); //app.UseEndpoints(endpoints => //{ // endpoints.MapControllers(); //}); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute(name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); }
public void Configure (Microsoft.AspNetCore.Builder.IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env) { app.UseHttpsRedirection(); app.UseRouting(); // Global cors policy app.UseCors(current => current .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader()); // Custom JWT auth middleware app.UseMiddleware <Infrastructure.Middlewares.JwtMiddleware>(); // Swagger middleware app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "v1"); }); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
public Program(Microsoft.AspNetCore.Hosting.IWebHostEnvironment webHostEnvironment) { WebHostEnvironment = webHostEnvironment;//look at explanation above constructor isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux); Console.WriteLine($"Platform {RuntimeInformation.OSDescription} {RuntimeInformation.OSArchitecture}"); var serverUri = new Uri("rtsp://*****:*****@175.139.231.133:554/Streaming/Channels/1"); //var credentials = new NetworkCredential("admin", "cctvsim14"); var connectionParameters = new ConnectionParameters(serverUri /*, credentials*/); var cancellationTokenSource = new CancellationTokenSource(); Task connectTask = ConnectAsync(connectionParameters, cancellationTokenSource.Token); Console.WriteLine("Press any key to cancel"); Console.ReadLine(); cancellationTokenSource.Cancel(); Console.WriteLine("Canceling"); connectTask.Wait(CancellationToken.None); }
/// <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; app.UseForwardedHeaders().UseCertificateForwarding(); // X-Forwarded-For if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/ServiceUnavailable"); } db.Database.EnsureCreated(); var dic = db.SystemSetting.ToDictionary(s => s.Name, s => s.Value); //初始化系统设置参数 foreach (var(key, value) in dic) { CommonHelper.SystemSettings.TryAdd(key, value); } app.UseBundles(); UseLuceneSearch(env, hangfire, luceneIndexerOptions); if (bool.Parse(Configuration["Https:Enabled"])) { app.UseHttpsRedirection().UseRewriter(new RewriteOptions().AddRedirectToNonWww()); // URL重写 } app.UseDefaultFiles().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.UseSession().UseCookiePolicy().UseMiniProfiler(); //注入Session app.UseRequestIntercept(); //启用网站请求拦截 app.UseStaticHttpContext(); //注入静态HttpContext对象 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(); //初始化定时任务 Console.WriteLine("网站启动完成"); }
public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } // app.Run() app.Map("/wechatWeb", WebF); }
public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env) { var webSocketOptions = new WebSocketOptions() { KeepAliveInterval = TimeSpan.FromSeconds(3600 * 24), ReceiveBufferSize = 1024 * 1024 * 20 }; app.UseWebSockets(webSocketOptions); app.Map("/createteam", createTeam); app.Map("/teambegain", teambegain); app.Map("/findTeam", findTeam); //if (env.IsDevelopment()) //{ // app.UseDeveloperExceptionPage(); //} //app.UseWebSockets(); //// app.useSt(); // For the wwwroot folder ////app.UseStaticFiles(new StaticFileOptions ////{ //// FileProvider = new PhysicalFileProvider( ////"F:\\MyProject\\VRPWithZhangkun\\MainApp\\VRPWithZhangkun\\VRPServer\\WebApp\\webHtml"), //// RequestPath = "/StaticFiles" ////}); ////app.Map("/postinfo", HandleMapdownload); //var webSocketOptions = new WebSocketOptions() //{ // KeepAliveInterval = TimeSpan.FromSeconds(60000 * 1000), // ReceiveBufferSize = 1024 * 1000 //}; //app.UseWebSockets(webSocketOptions); //// app.Map("/websocket", WebSocket); //app.Map("/websocket", builder => //{ // builder.Use(async (context, next) => // { // if (context.WebSockets.IsWebSocketRequest) // { // { // // Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}--累计登陆{sumVisitor},当前在线{sumVisitor - sumLeaver}"); // var webSocket = await context.WebSockets.AcceptWebSocketAsync(); // await Echo(webSocket); // } // } // await next(); // }); //}); //app.Map() }
public UserController( DatabaseService db, EmailSendingService send, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env, ILogger <UserController> logger) { this.db = db; this.send = send; this.env = env; this.logger = logger; }
// 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(); } AutofacContainer = app.ApplicationServices.GetAutofacRoot(); app.UseRouting(); app.UseMvc(); }
public FileController ( Context context, ISysFunctions sysFunctions, Microsoft.AspNetCore.Hosting.IWebHostEnvironment environment ) { _hostingEnvironment = environment; _context = context; _sysFunctions = sysFunctions; }
public static void SeedData(IServiceProvider services, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env, IConfiguration config) { using (var scope = services.GetRequiredService <IServiceScopeFactory>().CreateScope()) { var manager = scope.ServiceProvider.GetRequiredService <UserManager <UserAdditionalInfo> >(); var managerRole = scope.ServiceProvider.GetRequiredService <RoleManager <IdentityRole> >(); var context = scope.ServiceProvider.GetRequiredService <EFContext>(); SeedUsers(manager, managerRole, context); } }
public NodeRenderEngineBuilder( Microsoft.AspNetCore.Hosting.IWebHostEnvironment hostingEnvironment, IServiceProvider serviceProvider, IOptions <NodeRenderEngineOptions> options) { _serviceProvider = serviceProvider; _options = options.Value; if (string.IsNullOrEmpty(_options.ProjectDirectory)) { _options.ProjectDirectory = hostingEnvironment.WebRootPath; } }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IEventManager eventManager, AssemblyLoadContext assemblyLoadContext) { Application.EventManager = eventManager; Application.PluginLoadContext = assemblyLoadContext; if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseWebSockets(); app.UseMvc(); }
private StaticFileMiddleware CreateStaticFileMiddleware( RequestDelegate next, IHostingEnvironment hostingEnv, ILoggerFactory loggerFactory, SwaggerUIOptions options) { var staticFileOptions = new StaticFileOptions { RequestPath = string.IsNullOrEmpty(options.RoutePrefix) ? string.Empty : $"/{options.RoutePrefix}", FileProvider = new EmbeddedFileProvider(typeof(SwaggerUIMiddleware).GetTypeInfo().Assembly, EmbeddedFileNamespace), }; return new StaticFileMiddleware(next, hostingEnv, Options.Create(staticFileOptions), loggerFactory); }
public EventController(Microsoft.AspNetCore.Hosting.IWebHostEnvironment env, IStringLocalizer <EventController> localizer) { try { dbcontext = new MongoDBContext(); eventcollection = dbcontext.database.GetCollection <Event>("Events"); vollunteercollection = dbcontext.database.GetCollection <Volunteer>("Volunteers"); sponsorcollection = dbcontext.database.GetCollection <Sponsor>("Sponsors"); } catch { } _localizer = localizer; _eventsImportContext = new EventsImportContext(new EventsImportDataGateway()); }
public SwaggerUIMiddleware( RequestDelegate next, IHostingEnvironment hostingEnv, ILoggerFactory loggerFactory, SwaggerUIOptions options) { _options = options ?? new SwaggerUIOptions(); _staticFileMiddleware = CreateStaticFileMiddleware(next, hostingEnv, loggerFactory, options); _jsonSerializerOptions = new JsonSerializerOptions(); _jsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; _jsonSerializerOptions.IgnoreNullValues = true; _jsonSerializerOptions.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase, false)); }
public void Configure (Microsoft.AspNetCore.Builder.IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env) { //if (env.IsDevelopment()) //{ // app.UseDeveloperExceptionPage(); //} 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, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env) { //Add our new middleware to the pipeline app.UseRequestResponseLogging(); // global cors policy app.UseCors(x => x .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader()); app.UseDefaultFiles(); app.UseStaticFiles(); app.UseAuthentication(); //app.UseMvc(); }
/// <summary> /// asp.net core核心配置 /// </summary> /// <param name="configuration"></param> public Startup(IConfiguration configuration, IWebHostEnvironment env) { _env = env; void BindConfig() { Configuration = configuration; AppConfig.ConnString = configuration[nameof(AppConfig.ConnString)]; AppConfig.BaiduAK = configuration[nameof(AppConfig.BaiduAK)]; AppConfig.Redis = configuration[nameof(AppConfig.Redis)]; configuration.Bind("Imgbed:AliyunOSS", AppConfig.AliOssConfig); configuration.Bind("Imgbed:Gitlabs", AppConfig.GitlabConfigs); } ChangeToken.OnChange(configuration.GetReloadToken, BindConfig); BindConfig(); }
public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env) { //app.Map("/websocket", WebSocket); //var webSocketOptions = new WebSocketOptions() //{ // KeepAliveInterval = TimeSpan.FromSeconds(60), // ReceiveBufferSize = 1024 * 3 //}; //app.UseWebSockets(webSocketOptions); //app.Map("/notify", notify); //app.Map("/monitor", monitor); // Console.WriteLine($"启动TCP连接!{ env.po}"); }