Skip to content
Snippets Groups Projects
Commit c9fdda18 authored by esantangelo's avatar esantangelo
Browse files

commit

parent 98b28b5f
No related branches found
No related tags found
3 merge requests!20merge from develop,!16Feature/chat signalr,!15Feature/upload file
...@@ -6,6 +6,7 @@ using System.Text; ...@@ -6,6 +6,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using AutoMapper; using AutoMapper;
using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.HttpsPolicy;
...@@ -14,6 +15,7 @@ using Microsoft.AspNetCore.StaticFiles; ...@@ -14,6 +15,7 @@ using Microsoft.AspNetCore.StaticFiles;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
...@@ -79,7 +81,14 @@ namespace Tsi1.Api ...@@ -79,7 +81,14 @@ namespace Tsi1.Api
services.AddScoped<IEmailService, EmailService>(); services.AddScoped<IEmailService, EmailService>();
services.AddCors(); services.AddCors();
services.AddAuthorization(options =>
{
options.FallbackPolicy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
});
services.AddAuthentication(x => services.AddAuthentication(x =>
{ {
x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
...@@ -151,14 +160,6 @@ namespace Tsi1.Api ...@@ -151,14 +160,6 @@ namespace Tsi1.Api
c.DocumentTitle = "Tsi1 api"; c.DocumentTitle = "Tsi1 api";
}); });
var provider = new FileExtensionContentTypeProvider();
app.UseStaticFiles(new StaticFileOptions()
{
ContentTypeProvider = provider,
RequestPath = "/static"
}
); ;
app.UseRouting(); app.UseRouting();
app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()); app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
...@@ -166,6 +167,16 @@ namespace Tsi1.Api ...@@ -166,6 +167,16 @@ namespace Tsi1.Api
app.UseAuthentication(); app.UseAuthentication();
app.UseAuthorization(); 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 => app.UseEndpoints(endpoints =>
{ {
endpoints.MapControllers(); endpoints.MapControllers();
......
...@@ -14,5 +14,9 @@ ...@@ -14,5 +14,9 @@
<ProjectReference Include="..\Tsi1.BusinessLayer\Tsi1.BusinessLayer.csproj" /> <ProjectReference Include="..\Tsi1.BusinessLayer\Tsi1.BusinessLayer.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="StaticFiles\" />
</ItemGroup>
</Project> </Project>
...@@ -27,7 +27,7 @@ namespace Tsi1.BusinessLayer.Services ...@@ -27,7 +27,7 @@ namespace Tsi1.BusinessLayer.Services
{ {
_context = context; _context = context;
_mapper = mapper; _mapper = mapper;
_path = hostingEnvironment.ContentRootPath + "/wwwroot"; _path = hostingEnvironment.ContentRootPath + "/StaticFiles";
} }
public async Task<ServiceResult<string>> SaveFile(IFormFile file, string filePath) public async Task<ServiceResult<string>> SaveFile(IFormFile file, string filePath)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment