Init
This commit is contained in:
34
Prefab/Culture/CultureController.cs
Normal file
34
Prefab/Culture/CultureController.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using Microsoft.AspNetCore.Localization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Prefab.Culture;
|
||||
|
||||
/// <summary>
|
||||
/// Controller for setting the culture.
|
||||
/// </summary>
|
||||
[Route("[controller]/[action]")]
|
||||
public class CultureController : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Set the culture and redirect to the specified URL.
|
||||
/// </summary>
|
||||
/// <param name="culture"></param>
|
||||
/// <param name="redirectUri"></param>
|
||||
/// <returns>LocalRedirect ActionResult</returns>
|
||||
/// <remarks>
|
||||
/// Use LocalRedirect action result to prevent open redirect attacks.
|
||||
/// For more information <see href="https://learn.microsoft.com/en-us/aspnet/core/security/preventing-open-redirects?view=aspnetcore-9.0">Prevent open redirect attacks in ASP.NET Core</see>
|
||||
/// </remarks>
|
||||
public IActionResult Set(string? culture, string redirectUri)
|
||||
{
|
||||
if (culture != null)
|
||||
{
|
||||
HttpContext.Response.Cookies.Append(
|
||||
CookieRequestCultureProvider.DefaultCookieName,
|
||||
CookieRequestCultureProvider.MakeCookieValue(
|
||||
new RequestCulture(culture, culture)));
|
||||
}
|
||||
|
||||
return LocalRedirect(redirectUri);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user