public void CanValidateNull() { ElmahIoSettings settings = null; // ReSharper disable once ExpressionIsAlwaysNull Assert.Throws <ArgumentNullException>(() => settings.AssertSettings()); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IHttpContextAccessor accessor) { #region Logging loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); var elmahSts = new ElmahIoSettings { OnMessage = message => { message.Version = "v1.0"; message.Application = "SWA"; message.User = accessor.HttpContext.User.Identity.Name; }, }; //loggerFactory.AddElmahIo("e1ce5cbd905b42538c649f6e1d66351e", new Guid("adee8feb-4afb-4d2c-859d-30f729d47793")); //app.UseElmahIo("e1ce5cbd905b42538c649f6e1d66351e", new Guid("adee8feb-4afb-4d2c-859d-30f729d47793"), elmahSts); #endregion #region Configurações MVC app.UseCors(c => { c.AllowAnyHeader(); c.AllowAnyMethod(); c.AllowAnyOrigin(); }); app.UseStaticFiles(); app.UseAuthentication(); app.UseMvc(); #endregion #region Swagger if (env.IsProduction()) { // Se não tiver um token válido no browser não funciona. // Descomente para ativar a segurança. // app.UseSwaggerAuthorized(); } app.UseSwagger(); app.UseSwaggerUI(s => { s.SwaggerEndpoint("/swagger/v1/swagger.json", "SWA API v1.0"); }); #endregion }
public static ElmahIoSettings AssertSettings(this ElmahIoSettings settings) { if (settings == null) { throw new ArgumentNullException(nameof(settings), "Input settings for elmah.io"); } return(settings); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IHttpContextAccessor accessor, ILoggerFactory loggerFactory) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseAuthentication(); app.UseMvc(); //get http container copy and use on memmory BUS CoreMemoryBus.ContainerAccessor = () => accessor.HttpContext.RequestServices; #region Logging loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); loggerFactory.AddElmahIo("db89eadb778d4de08a85296cb48b84e4", new Guid("5e299c42-e14a-4ebe-9d38-19f7cf650266")); var elmahSts = new ElmahIoSettings { OnMessage = message => { message.Version = "v1.0"; message.Application = "Diretiva Tech"; message.User = accessor.HttpContext.User.Identity.Name; }, }; app.UseElmahIo("db89eadb778d4de08a85296cb48b84e4", new Guid("5e299c42-e14a-4ebe-9d38-19f7cf650266"), elmahSts); app.UseElmahIo(); #endregion }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IHttpContextAccessor accessor) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); var elmahSts = new ElmahIoSettings { OnMessage = message => { message.Version = "v1.0"; message.Application = "Eventos.IO"; message.User = accessor.HttpContext.User.Identity.Name; }, }; loggerFactory.AddElmahIo("e1ce5cbd905b42538c649f6e1d66351e", new Guid("19ad15fd-5158-4b7a-b36d-ab56dfe4500a")); app.UseElmahIo("e1ce5cbd905b42538c649f6e1d66351e", new Guid("19ad15fd-5158-4b7a-b36d-ab56dfe4500a"), elmahSts); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseCors(c => { c.AllowAnyHeader(); c.AllowAnyMethod(); c.AllowAnyOrigin(); }); app.UseStaticFiles(); app.UseMvc(); //está dando erro??? //app.UseSwaggerAuthorized(); app.UseSwagger(); app.UseSwaggerUI(s => { s.SwaggerEndpoint("/swagger/v1/swagger.json", "Eventos.IO API v1.0"); }); InMemoryBus.ContainerAccessor = () => accessor.HttpContext.RequestServices; }
/// <summary> /// Configurar aplicacação /// </summary> /// <param name="app">Aplicação</param> /// <param name="env">Define o ambiente (Desenvolvimento ou Produção)</param> /// <param name="loggerFactory">Monitora erros da aplicação para o ElmahIo</param> /// <param name="accessor"></param> public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IHttpContextAccessor accessor) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); var elmahSts = new ElmahIoSettings { OnMessage = message => { message.Version = "v1.0"; message.Application = "UsuariosAPI"; message.User = "******"; }, }; loggerFactory.AddElmahIo("e1ce5cbd905b42538c649f6e1d66351e", new Guid("19ad15fd-5158-4b7a-b36d-ab56dfe4500a")); app.UseElmahIo("56fe8edb8db84a22a619c17c265bd343", new Guid("7c905d1b-ca05-426c-81f4-84cbc3eca44f"), elmahSts); app.UseCors(c => { c.AllowAnyHeader(); c.AllowAnyMethod(); c.AllowAnyOrigin(); }); app.UseStaticFiles(); app.UseMvc(); app.UseSwagger(); app.UseSwaggerUI(s => { s.SwaggerEndpoint("/swagger/v1/swagger.json", "UsuariosEP.IO API v1.0"); }); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IHttpContextAccessor accessor) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); var elmahSts = new ElmahIoSettings { OnMessage = message => { message.Version = "v1.0"; message.Application = "Eventos.IO"; message.User = accessor.HttpContext.User.Identity.Name; }, }; loggerFactory.AddElmahIo("e1ce5cbd905b42538c649f6e1d66351e", new Guid("19ad15fd-5158-4b7a-b36d-ab56dfe4500a")); app.UseElmahIo("e1ce5cbd905b42538c649f6e1d66351e", new Guid("19ad15fd-5158-4b7a-b36d-ab56dfe4500a"), elmahSts); var jwtAppSettingOptions = Configuration.GetSection(nameof(JwtTokenOptions)); var tokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidIssuer = jwtAppSettingOptions[nameof(JwtTokenOptions.Issuer)], ValidateAudience = true, ValidAudience = jwtAppSettingOptions[nameof(JwtTokenOptions.Audience)], ValidateIssuerSigningKey = true, IssuerSigningKey = _signingKey, RequireExpirationTime = true, ValidateLifetime = true, ClockSkew = TimeSpan.Zero }; app.UseJwtBearerAuthentication(new JwtBearerOptions { AutomaticAuthenticate = true, AutomaticChallenge = true, TokenValidationParameters = tokenValidationParameters }); app.UseCors(c => { c.AllowAnyHeader(); c.AllowAnyMethod(); c.AllowAnyOrigin(); }); app.UseStaticFiles(); app.UseIdentity(); app.UseMvc(); app.UseSwaggerAuthorized(); app.UseSwagger(); app.UseSwaggerUI(s => { s.SwaggerEndpoint("/swagger/v1/swagger.json", "Eventos.IO API v1.0"); }); InMemoryBus.ContainerAccessor = () => accessor.HttpContext.RequestServices; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IHttpContextAccessor acessor, ILoggerFactory loggerFactory) { // Só colocando este código foi possível habilitar a comunicação entre o Angular e os serviços Asp Net app.Use(async(ctx, next) => { await next(); if (ctx.Response.StatusCode == 204) { ctx.Response.ContentLength = 0; } }); 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(); } var elmahSts = new ElmahIoSettings { OnMessage = message => { message.Version = "v1.0"; message.Application = "Eventos.IO"; message.User = acessor.HttpContext.User.Identity.Name; message.Source = "GlobalActionLoggerFilter"; message.Hostname = acessor.HttpContext.Request.Host.ToString(); message.Url = acessor.HttpContext.Request.GetDisplayUrl(); } }; loggerFactory.AddElmahIo("ccde64921fbd4ef69bd01c1a097251af", new Guid("809c3d10-450a-4395-bd4a-7fa23aaae94f")); app.UseElmahIo("ccde64921fbd4ef69bd01c1a097251af", new Guid("809c3d10-450a-4395-bd4a-7fa23aaae94f"), elmahSts); // ssbcvp - voltar aqui - tirei este código // app.UseHttpsRedirection(); // Garante que a aplicação só responda para domínios que ela conheça, só vou aceitar requisições de um determinado site, ou requests de um determinado verbo // Por enquanto estamos deixando tudo liberado para requisições externas, logo abaixo tem exemplo de como restringir alguma coisa para requisiçoes externas // Por padrão as requisições externas são restringidas se não usar o Cors app.UseCors(c => { c.AllowAnyHeader(); c.AllowAnyMethod(); c.AllowAnyOrigin(); // Exemplo de restrição de utilização da sua api, requisições de fora só aceitarão os 2 sites abaixo // e somente aceitará POSTs, só serve para requisições externas // c.WithOrigins("www.eventos.io,www.site.com"); // c.WithMethods("POST"); }); app.UseStaticFiles(); // Microsoft sugeriu incluir isto no lugar do UseJwtBearerAuthentication que está obsoleto // Código veio de https://docs.microsoft.com/pt-br/aspnet/core/migration/1x-to-2x/identity-2x?view=aspnetcore-2.2 // Token(core 2.2) - usado no lugar de UseIdentity que está obsoleto app.UseAuthentication(); app.UseMvc(); // app.UseSwaggerAuthorized(); app.UseSwagger(); app.UseSwaggerUI(s => { s.SwaggerEndpoint("/swagger/v1/swagger.json", "Eventos.IO API V1.0"); }); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IHttpContextAccessor accessor) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); var elmahSts = new ElmahIoSettings { OnMessage = message => { message.Version = "v1.0"; message.Application = "Eventos.IO"; message.User = accessor.HttpContext.User.Identity.Name; }, }; loggerFactory.AddElmahIo("e1ce5cbd905b42538c649f6e1d66351e", new Guid("19ad15fd-5158-4b7a-b36d-ab56dfe4500a")); app.UseElmahIo("e1ce5cbd905b42538c649f6e1d66351e", new Guid("19ad15fd-5158-4b7a-b36d-ab56dfe4500a"), elmahSts); app.UseElmahIo(); app.UseAuthentication(); var jwtAppSettingOptions = Configuration.GetSection(nameof(JwtTokenOptions)); var tokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidIssuer = jwtAppSettingOptions[nameof(JwtTokenOptions.Issuer)], ValidateAudience = true, ValidAudience = jwtAppSettingOptions[nameof(JwtTokenOptions.Audience)], ValidateIssuerSigningKey = true, IssuerSigningKey = _signingKey, RequireExpirationTime = true, ValidateLifetime = true, ClockSkew = TimeSpan.Zero }; app.UseCors(c => { c.AllowAnyHeader(); c.AllowAnyMethod(); c.AllowAnyOrigin(); }); app.UseStaticFiles(); app.UseIdentity(); app.UseMvc(); app.UseSwaggerAuthorized(); app.UseSwagger(); app.UseSwaggerUI(s => { s.SwaggerEndpoint("/swagger/v1/swagger.json", "Eventos.IO API v1.0"); }); InMemoryBus.ContainerAccessor = () => accessor.HttpContext.RequestServices; #region //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(); #endregion }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IHttpContextAccessor accessor) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); var elmahSts = new ElmahIoSettings { OnMessage = message => { message.Version = "v1.0"; message.Application = "Eventos.IO"; message.User = accessor.HttpContext.User.Identity.Name; }, }; //these guids are paid keys -- this is just for demo purpose loggerFactory.AddElmahIo("0b8f6c34-6e07-4dae-8d6b-5f35f84e52a7", new Guid("ae189cd6-4491-49ae-8f38-bf49f5f36627")); //these guids are paid keys -- this is just for demo purpose app.UseElmahIo("0b8f6c34-6e07-4dae-8d6b-5f35f84e52a7", new Guid("ae189cd6-4491-49ae-8f38-bf49f5f36627"), elmahSts); var jwtAppSettingOptions = Configuration.GetSection(nameof(JwtTokenOptions)); var tokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidIssuer = jwtAppSettingOptions[nameof(JwtTokenOptions.Issuer)], ValidateAudience = true, ValidAudience = jwtAppSettingOptions[nameof(JwtTokenOptions.Audience)], ValidateIssuerSigningKey = true, IssuerSigningKey = _signingKey, RequireExpirationTime = true, ValidateLifetime = true, ClockSkew = TimeSpan.Zero }; app.UseJwtBearerAuthentication(new JwtBearerOptions { AutomaticAuthenticate = true, AutomaticChallenge = true, TokenValidationParameters = tokenValidationParameters }); app.UseCors(c => { c.AllowAnyHeader(); c.AllowAnyMethod(); c.AllowAnyOrigin(); }); app.UseStaticFiles(); app.UseIdentity(); app.UseMvc(); app.UseSwaggerAuthorized(); app.UseSwagger(); app.UseSwaggerUI(s => { s.SwaggerEndpoint("/swagger/v1/swagger.json", "Eventos.IO API v1.0"); }); InMemoryBus.ContainerAccessor = () => accessor.HttpContext.RequestServices; }
// 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, IHttpContextAccessor accessor) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); var elmahSts = new ElmahIoSettings { OnMessage = message => { message.Version = "v1.0"; message.Application = "Evento.IO"; message.User = accessor.HttpContext.User.Identity.Name; } }; loggerFactory.AddElmahIo("81378002d1044733af806b28394199d0", new Guid("b7411135-9483-4675-945c-067f8544bf00")); app.UseElmahIo("81378002d1044733af806b28394199d0", new Guid("b7411135-9483-4675-945c-067f8544bf00"), elmahSts); var jwtAppSettingOptions = Configuration.GetSection(nameof(JwtTokenOptions)); var tokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidIssuer = jwtAppSettingOptions[nameof(JwtTokenOptions.Issuer)], ValidateAudience = true, ValidAudience = jwtAppSettingOptions[nameof(JwtTokenOptions.Audience)], ValidateIssuerSigningKey = true, IssuerSigningKey = _signingKey, RequireExpirationTime = true, ValidateLifetime = true, ClockSkew = TimeSpan.Zero }; app.UseJwtBearerAuthentication(new JwtBearerOptions { AutomaticAuthenticate = true, AutomaticChallenge = true, TokenValidationParameters = tokenValidationParameters }); app.UseCors(c => { c.AllowAnyHeader(); c.AllowAnyMethod(); c.AllowAnyOrigin(); }); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseStaticFiles(); app.UseIdentity(); app.UseMvc(); app.UseSwaggerAuthorized(); app.UseSwagger(); app.UseSwaggerUI(s => { s.SwaggerEndpoint("/swagger/v1/swagger.json", "Eventos.IO API v1.0"); }); InMemoryBus.ContainerAccessor = () => accessor.HttpContext.RequestServices; }