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 DigitalData.Core.DTO;
|
||||||
using EnvelopeGenerator.Application.Resources;
|
using EnvelopeGenerator.Application.Resources;
|
||||||
using EnvelopeGenerator.Application.DTOs;
|
using EnvelopeGenerator.Application.DTOs;
|
||||||
|
using Microsoft.AspNetCore.Localization;
|
||||||
|
|
||||||
namespace EnvelopeGenerator.Web.Controllers
|
namespace EnvelopeGenerator.Web.Controllers
|
||||||
{
|
{
|
||||||
@ -214,6 +215,16 @@ namespace EnvelopeGenerator.Web.Controllers
|
|||||||
return Ok(new { EnvelopeUuid = envelopeUuid, ReceiverSignature = receiverSignature });
|
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();
|
public IActionResult Error404() => this.ViewError404();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -22,6 +22,21 @@ try
|
|||||||
{
|
{
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
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.Logging.ClearProviders();
|
||||||
builder.Host.UseNLog();
|
builder.Host.UseNLog();
|
||||||
|
|
||||||
@ -159,7 +174,9 @@ try
|
|||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
app.UseCookieBasedLocalizer("de_DE", "en_US");
|
app.UseCookieBasedLocalizer("de_DE", "en_US");
|
||||||
|
|
||||||
|
app.UseCors("SameOriginPolicy");
|
||||||
|
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
app.MapFallbackToController("Error404", "Home");
|
app.MapFallbackToController("Error404", "Home");
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AdminPassword": "dd",
|
"AdminPassword": "dd",
|
||||||
|
"AllowedOrigins": [ "https://localhost:7202" ],
|
||||||
"NLog": {
|
"NLog": {
|
||||||
"throwConfigExceptions": true,
|
"throwConfigExceptions": true,
|
||||||
"targets": {
|
"targets": {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user