* https://dev.azure.com/umbraco/D-Team%20Tracker/_workitems/edit/6587 - Migrated DictionaryController, TinyMceController and UpdateCheckController * Removing connection string and changing to use the right variable Co-authored-by: Elitsa Marinovska <elm@umbraco.dk>
49 lines
1.3 KiB
C#
49 lines
1.3 KiB
C#
using System;
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
namespace Umbraco.Web.Common.AspNetCore
|
|
{
|
|
public class AspNetCoreCookieManager : ICookieManager
|
|
{
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
|
|
public AspNetCoreCookieManager(IHttpContextAccessor httpContextAccessor)
|
|
{
|
|
_httpContextAccessor = httpContextAccessor;
|
|
}
|
|
|
|
public void ExpireCookie(string cookieName)
|
|
{
|
|
var httpContext = _httpContextAccessor.HttpContext;
|
|
|
|
if (httpContext is null) return;
|
|
|
|
var cookieValue = httpContext.Request.Cookies[cookieName];
|
|
|
|
httpContext.Response.Cookies.Append(cookieName, cookieValue ?? string.Empty, new CookieOptions()
|
|
{
|
|
Expires = DateTime.Now.AddYears(-1)
|
|
});
|
|
}
|
|
|
|
public string GetCookieValue(string cookieName)
|
|
{
|
|
return _httpContextAccessor.HttpContext?.Request.Cookies[cookieName];
|
|
}
|
|
|
|
public void SetCookieValue(string cookieName, string value)
|
|
{
|
|
_httpContextAccessor.HttpContext?.Response.Cookies.Append(cookieName, value, new CookieOptions()
|
|
{
|
|
|
|
});
|
|
}
|
|
|
|
public bool HasCookie(string cookieName)
|
|
{
|
|
return !(GetCookieValue(cookieName) is null);
|
|
}
|
|
|
|
}
|
|
}
|