demo20230512/Controllers/Api/SetCultureController.cs

36 lines
1.0 KiB
C#
Raw Permalink Normal View History

2023-05-12 10:20:28 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using Resources.Helper;
namespace Weee.Controllers
{
public class SetCultureController : ApiController
{
// POST api/<controller>
[AllowAnonymous]
[Route("api/SetCulture/{culture}")]
[HttpPost]
public void Post(string culture)
{
culture = CultureHelper.GetImplementedCulture(culture);
// Save culture in a cookie
HttpCookie cookie = HttpContext.Current.Request.Cookies["_culture"]; // 改多國語系的地方
if (cookie != null)
cookie.Value = culture; // update cookie value
else
{
cookie = new HttpCookie("_culture");
cookie.Value = culture;
cookie.Expires = DateTime.Now.AddYears(1);
}
HttpContext.Current.Response.Cookies.Add(cookie);
}
}
}