SPEC:
_ aggiunto gestione mimetype coinfigurabile - fix AppUri base
This commit is contained in:
+33
-2
@@ -3,6 +3,8 @@ using Blazored.SessionStorage;
|
||||
using Microsoft.AspNetCore.Authentication.Negotiate;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
using Microsoft.AspNetCore.StaticFiles;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using MP.SPEC.Components;
|
||||
using MP.SPEC.Data;
|
||||
@@ -31,7 +33,7 @@ ConfigurationManager configuration = builder.Configuration;
|
||||
|
||||
|
||||
// REDIS setup
|
||||
logger.Info("Setup REDIS");
|
||||
logger.Info("Setup REDIS");
|
||||
string connStringRedis = configuration.GetConnectionString("Redis");
|
||||
//string connStringRedis = ConfMan.GetConnectionString("RedisAdmin");
|
||||
string redisSrvAddr = connStringRedis.Substring(0, connStringRedis.IndexOf(":"));
|
||||
@@ -40,7 +42,7 @@ var redisMultiplexer = ConnectionMultiplexer.Connect(connStringRedis);
|
||||
|
||||
|
||||
// Add services to the container.
|
||||
logger.Info("Setup Auth");
|
||||
logger.Info("Setup Auth");
|
||||
builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme)
|
||||
.AddNegotiate();
|
||||
|
||||
@@ -66,6 +68,10 @@ logger.Info("Aggiunti services");
|
||||
var app = builder.Build();
|
||||
logger.Info("Build App");
|
||||
|
||||
|
||||
// aggiunt base URL x routing corretto
|
||||
app.UsePathBase(configuration.GetValue<string>("SpecialConf:AppUrl"));
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (!app.Environment.IsDevelopment())
|
||||
{
|
||||
@@ -82,12 +88,37 @@ app.UseStaticFiles();
|
||||
string BasePathOdlReturn = configuration.GetValue<string>("ServerConf:BasePathOdlReturn") ?? configuration.GetValue<string>("OptConf:BasePathOdlReturn") ?? "";
|
||||
if (!string.IsNullOrEmpty(BasePathOdlReturn))
|
||||
{
|
||||
// preparo mappings opzionali se presenti in conf...
|
||||
var provider = new FileExtensionContentTypeProvider();
|
||||
// vedere https://code-maze.com/dotnet-appsettings-json-content-to-dictionary/
|
||||
var mimeSection = configuration.GetSection("ServerConf:MimeMappings");
|
||||
if (mimeSection != null)
|
||||
{
|
||||
var mimeDict = mimeSection
|
||||
.AsEnumerable()
|
||||
.Where(x => !string.IsNullOrWhiteSpace(x.Value))
|
||||
.ToDictionary(x => x.Key.Replace("ServerConf:MimeMappings:", ""), x => x.Value);
|
||||
// se ne ho trovati
|
||||
if (mimeDict != null && mimeDict.Count > 0)
|
||||
{
|
||||
// li aggiungo! vedere
|
||||
// https://thechrisgreen.com/2022/05/add-a-mime-type-to-an-asp-net-core-net-6-app/
|
||||
// https://harrybellamy.com/posts/getting-mime-types-from-file-extensions-in-net-core/
|
||||
foreach (var item in mimeDict)
|
||||
{
|
||||
// Add new mappings
|
||||
provider.Mappings[item.Key] = item.Value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// verifico esista folder
|
||||
if (Directory.Exists(BasePathOdlReturn))
|
||||
{
|
||||
// gestione cartella x file ritornati x ODL
|
||||
app.UseStaticFiles(new StaticFileOptions
|
||||
{
|
||||
ContentTypeProvider = provider,
|
||||
FileProvider = new PhysicalFileProvider(BasePathOdlReturn),
|
||||
RequestPath = "/RET_DATA",
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user