v10: Fix build warnings in Web.Common (#12349)
* Run code cleanup * Run dotnet format * Start manual cleanup in Web.Common * Finish up manual cleanup * Fix tests * Fix up InMemoryModelFactory.cs * Inject proper macroRenderer * Update src/Umbraco.Web.Common/Filters/JsonDateTimeFormatAttribute.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Web.Common/Filters/ValidateUmbracoFormRouteStringAttribute.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Fix based on review Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk> Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>
This commit is contained in:
@@ -1,49 +1,34 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Umbraco.Cms.Core.Web;
|
||||
|
||||
namespace Umbraco.Cms.Web.Common.AspNetCore
|
||||
namespace Umbraco.Cms.Web.Common.AspNetCore;
|
||||
|
||||
public class AspNetCoreCookieManager : ICookieManager
|
||||
{
|
||||
public class AspNetCoreCookieManager : ICookieManager
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
public AspNetCoreCookieManager(IHttpContextAccessor httpContextAccessor) =>
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
|
||||
public void ExpireCookie(string cookieName)
|
||||
{
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
HttpContext? httpContext = _httpContextAccessor.HttpContext;
|
||||
|
||||
public AspNetCoreCookieManager(IHttpContextAccessor httpContextAccessor)
|
||||
if (httpContext is null)
|
||||
{
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
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) => _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) => !(GetCookieValue(cookieName) is null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user