36 lines
1.0 KiB
C#
36 lines
1.0 KiB
C#
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);
|
|
}
|
|
}
|
|
} |