2020-02-18 08:32:06 +01:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2020-03-13 18:44:58 +11:00
|
|
|
|
using Microsoft.AspNetCore.Http.Features;
|
2020-02-18 08:32:06 +01:00
|
|
|
|
using Umbraco.Net;
|
|
|
|
|
|
|
2020-03-27 11:39:17 +01:00
|
|
|
|
namespace Umbraco.Web.Common.AspNetCore
|
2020-02-18 08:32:06 +01:00
|
|
|
|
{
|
2020-02-24 16:18:47 +01:00
|
|
|
|
internal class AspNetCoreSessionIdResolver : ISessionIdResolver
|
2020-02-18 08:32:06 +01:00
|
|
|
|
{
|
|
|
|
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
|
|
|
|
|
2020-02-24 16:18:47 +01:00
|
|
|
|
public AspNetCoreSessionIdResolver(IHttpContextAccessor httpContextAccessor)
|
2020-02-18 08:32:06 +01:00
|
|
|
|
{
|
|
|
|
|
|
_httpContextAccessor = httpContextAccessor;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-27 11:39:17 +01:00
|
|
|
|
|
2020-03-13 18:44:58 +11:00
|
|
|
|
public string SessionId
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2020-03-24 12:11:46 +11:00
|
|
|
|
var httpContext = _httpContextAccessor?.HttpContext;
|
2020-03-13 18:44:58 +11:00
|
|
|
|
// If session isn't enabled this will throw an exception so we check
|
2020-03-24 12:11:46 +11:00
|
|
|
|
var sessionFeature = httpContext?.Features.Get<ISessionFeature>();
|
2020-03-13 18:44:58 +11:00
|
|
|
|
return sessionFeature != null
|
2020-03-24 12:11:46 +11:00
|
|
|
|
? httpContext?.Session?.Id
|
2020-03-13 18:44:58 +11:00
|
|
|
|
: "0";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-02-18 08:32:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|