From c9fdda18f7f71bded8d1a851173251fa4ed85eed Mon Sep 17 00:00:00 2001 From: esantangelo <enzo020895@gmail.com> Date: Sun, 1 Nov 2020 18:25:31 -0300 Subject: [PATCH] commit --- Tsi1.Api/Tsi1.Api/Startup.cs | 29 +++++++++++++------ Tsi1.Api/Tsi1.Api/Tsi1.Api.csproj | 4 +++ .../Services/FileService.cs | 2 +- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Tsi1.Api/Tsi1.Api/Startup.cs b/Tsi1.Api/Tsi1.Api/Startup.cs index 426205b..854ba8a 100644 --- a/Tsi1.Api/Tsi1.Api/Startup.cs +++ b/Tsi1.Api/Tsi1.Api/Startup.cs @@ -6,6 +6,7 @@ using System.Text; using System.Threading.Tasks; using AutoMapper; using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpsPolicy; @@ -14,6 +15,7 @@ using Microsoft.AspNetCore.StaticFiles; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -79,7 +81,14 @@ namespace Tsi1.Api services.AddScoped<IEmailService, EmailService>(); services.AddCors(); - + + services.AddAuthorization(options => + { + options.FallbackPolicy = new AuthorizationPolicyBuilder() + .RequireAuthenticatedUser() + .Build(); + }); + services.AddAuthentication(x => { x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; @@ -151,14 +160,6 @@ namespace Tsi1.Api c.DocumentTitle = "Tsi1 api"; }); - var provider = new FileExtensionContentTypeProvider(); - app.UseStaticFiles(new StaticFileOptions() - { - ContentTypeProvider = provider, - RequestPath = "/static" - } - ); ; - app.UseRouting(); app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()); @@ -166,6 +167,16 @@ namespace Tsi1.Api app.UseAuthentication(); app.UseAuthorization(); + var provider = new FileExtensionContentTypeProvider(); + app.UseStaticFiles(new StaticFileOptions() + { + ContentTypeProvider = provider, + FileProvider = new PhysicalFileProvider( + Path.Combine(env.ContentRootPath, "StaticFiles")), + RequestPath = "/static" + } + ); + app.UseEndpoints(endpoints => { endpoints.MapControllers(); diff --git a/Tsi1.Api/Tsi1.Api/Tsi1.Api.csproj b/Tsi1.Api/Tsi1.Api/Tsi1.Api.csproj index 1ed4b44..7fa4dab 100644 --- a/Tsi1.Api/Tsi1.Api/Tsi1.Api.csproj +++ b/Tsi1.Api/Tsi1.Api/Tsi1.Api.csproj @@ -14,5 +14,9 @@ <ProjectReference Include="..\Tsi1.BusinessLayer\Tsi1.BusinessLayer.csproj" /> </ItemGroup> + <ItemGroup> + <Folder Include="StaticFiles\" /> + </ItemGroup> + </Project> diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Services/FileService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Services/FileService.cs index eaa3d74..5e7fcd6 100644 --- a/Tsi1.Api/Tsi1.BusinessLayer/Services/FileService.cs +++ b/Tsi1.Api/Tsi1.BusinessLayer/Services/FileService.cs @@ -27,7 +27,7 @@ namespace Tsi1.BusinessLayer.Services { _context = context; _mapper = mapper; - _path = hostingEnvironment.ContentRootPath + "/wwwroot"; + _path = hostingEnvironment.ContentRootPath + "/StaticFiles"; } public async Task<ServiceResult<string>> SaveFile(IFormFile file, string filePath) -- GitLab