// 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, IWriteToFileText writeToFileText) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { ExceptionHandlerConfigurations.Configure(app, loggerFactory, writeToFileText); } app.UseStaticFiles(); if (string.IsNullOrWhiteSpace(env.WebRootPath)) { env.WebRootPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot"); } app.UseStaticFiles(new StaticFileOptions() { FileProvider = new PhysicalFileProvider( Path.Combine(env.WebRootPath, "uploads")), RequestPath = new PathString("/uploads") }); app.UseForwardedHeaders(new ForwardedHeadersOptionsht { ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto }); app.UseHttpsRedirection(); app.UseHsts(); app.AddCors(options => options.AddPolicy("AllowCors", builder => { builder .SetIsOriginAllowed(x => { return ( x.ToLower().IndexOf("localhost") >= 0 || x.ToLower().IndexOf("produrl") >= 0 ); }) .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials(); })); // 2. Enable authentication middleware app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "api/{controller}/{action=Index}/{id?}"); }); }
// 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) { app.AddSwagger(); app.AddCors(); app.AddExceptionHandling(env, serviceProvider); app.UseHttpsRedirection(); app.ConfigureMvcStaticFilesAndRouting(env); }
// 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, IHateoasHelper hateoasHelper, IApiInfoService apiInfoService) { 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 appSettingsSection = Configuration.GetSection("AppSettings"); var appSettings = appSettingsSection.Get <AppSettings>(); app.AddCors(appSettings.CorsAllowedOrigins, appSettings.CorsAllowedMethods, appSettings.CorsAllowedHeaders); app.UseAuthentication(); app.UseUIOfSwagger(appSettings.SwaggerEndPointJsonUrl, appSettings.SwaggerEndPointTitle); app.UseMiddleware <RequestResponseLoggingMiddleware>(); app.UseMiddleware <ApiKeyMiddleware <User, ApiKey> >(); loggerFactory.AddLog4Net(); app.UseHttpsRedirection(); app.UseMvc(b => { b.Select().Expand().Filter().OrderBy().MaxTop(100).Count(); b.MapODataServiceRoute("odata", "odata", GetEdmModel()); }); app.UseApiVersioning(); // Inicializando los colaboradores para Hateoas segĂșn las APIs que hayamos configurado apiInfoService.GetAll().ToList().ForEach(installedApi => hateoasHelper.AddCollaborator(installedApi.ApiType, installedApi.BaseHref)); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.AddCors(); app.UseMvc(); }