26 lines
749 B
C#
26 lines
749 B
C#
|
|
using Microsoft.AspNetCore.Mvc;
|
||
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||
|
|
|
||
|
|
namespace SoroushAsadi.Pages;
|
||
|
|
|
||
|
|
/// <summary>POST /locale — sets the locale cookie and redirects back.</summary>
|
||
|
|
[IgnoreAntiforgeryToken]
|
||
|
|
public class LocalePageModel : PageModel
|
||
|
|
{
|
||
|
|
public IActionResult OnPost(string locale, string returnUrl = "/")
|
||
|
|
{
|
||
|
|
if (locale is not "fa" and not "en") locale = "fa";
|
||
|
|
|
||
|
|
Response.Cookies.Append("locale", locale, new CookieOptions
|
||
|
|
{
|
||
|
|
Expires = DateTimeOffset.UtcNow.AddYears(1),
|
||
|
|
HttpOnly = false,
|
||
|
|
SameSite = SameSiteMode.Lax,
|
||
|
|
Path = "/"
|
||
|
|
});
|
||
|
|
|
||
|
|
if (!Url.IsLocalUrl(returnUrl)) returnUrl = "/";
|
||
|
|
return LocalRedirect(returnUrl);
|
||
|
|
}
|
||
|
|
}
|