Erweiterte Funktionalität durch Hinzufügen eines Endpunkts zur Zuweisung von Sprachen zu Cookies. Implementierte eine CORS-Richtlinie, die die Konfiguration von Ursprüngen über appsettings.json ermöglicht.
This commit is contained in:
parent
22a3ec914d
commit
84442410a5
@ -13,6 +13,7 @@ using Microsoft.Extensions.Localization;
|
||||
using DigitalData.Core.DTO;
|
||||
using EnvelopeGenerator.Application.Resources;
|
||||
using EnvelopeGenerator.Application.DTOs;
|
||||
using Microsoft.AspNetCore.Localization;
|
||||
|
||||
namespace EnvelopeGenerator.Web.Controllers
|
||||
{
|
||||
@ -214,6 +215,16 @@ namespace EnvelopeGenerator.Web.Controllers
|
||||
return Ok(new { EnvelopeUuid = envelopeUuid, ReceiverSignature = receiverSignature });
|
||||
}
|
||||
|
||||
[HttpPost("{language}")]
|
||||
public IActionResult PostLanguage([FromQuery] string language)
|
||||
{
|
||||
Response.Cookies.Append(CookieRequestCultureProvider.DefaultCookieName, CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(language)), new CookieOptions()
|
||||
{
|
||||
Expires = DateTimeOffset.UtcNow.AddYears(1)
|
||||
});
|
||||
return Redirect(Request.Headers["Referer"].ToString());
|
||||
}
|
||||
|
||||
public IActionResult Error404() => this.ViewError404();
|
||||
}
|
||||
}
|
||||
@ -22,6 +22,21 @@ try
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
var allowedOrigins = builder.Configuration.GetSection("AllowedOrigins").Get<string[]>() ??
|
||||
throw new InvalidOperationException("AllowedOrigins section is missing in the configuration.");
|
||||
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("SameOriginPolicy", builder =>
|
||||
{
|
||||
builder.WithOrigins(allowedOrigins)
|
||||
.SetIsOriginAllowedToAllowWildcardSubdomains()
|
||||
.AllowCredentials()
|
||||
.AllowAnyMethod()
|
||||
.AllowAnyHeader();
|
||||
});
|
||||
});
|
||||
|
||||
builder.Logging.ClearProviders();
|
||||
builder.Host.UseNLog();
|
||||
|
||||
@ -161,6 +176,8 @@ try
|
||||
|
||||
app.UseCookieBasedLocalizer("de_DE", "en_US");
|
||||
|
||||
app.UseCors("SameOriginPolicy");
|
||||
|
||||
app.MapControllers();
|
||||
app.MapFallbackToController("Error404", "Home");
|
||||
app.Run();
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
}
|
||||
},
|
||||
"AdminPassword": "dd",
|
||||
"AllowedOrigins": [ "https://localhost:7202" ],
|
||||
"NLog": {
|
||||
"throwConfigExceptions": true,
|
||||
"targets": {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user