| 1234567891011121314151617181920212223242526272829303132 |
- using Abp.Timing;
- using Microsoft.AspNetCore.Localization;
- namespace VberZero.Localization;
- public class DefaultLocalizationCookieMiddleware
- {
- private readonly RequestDelegate _next;
- private readonly string _cookieName = VzConsts.LocalizationCookieName;
- public DefaultLocalizationCookieMiddleware(RequestDelegate next)
- {
- _next = next;
- }
- public async Task Invoke(HttpContext context)
- {
- var cookie = context.Request.Cookies[_cookieName];
- if (cookie == null)
- {
- string cookieValue = CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(VzConsts.DefaultLanguage, VzConsts.DefaultLanguage));
- context.Response.Cookies.Append(VzConsts.LocalizationCookieName, cookieValue, new CookieOptions()
- {
- Expires = Clock.Now.AddYears(2),
- HttpOnly = true
- });
- }
- await _next(context);
- }
- }
|