fix issue referencing ClaimsPrincipal UserId extension method
This commit is contained in:
parent
38c468a204
commit
2dec3195ac
|
@ -326,11 +326,8 @@
|
||||||
// get other request attributes
|
// get other request attributes
|
||||||
string url = Context.Request.GetEncodedUrl();
|
string url = Context.Request.GetEncodedUrl();
|
||||||
string referrer = (Context.Request.Headers[HeaderNames.Referer] != StringValues.Empty) ? Context.Request.Headers[HeaderNames.Referer] : "";
|
string referrer = (Context.Request.Headers[HeaderNames.Referer] != StringValues.Empty) ? Context.Request.Headers[HeaderNames.Referer] : "";
|
||||||
int? userid = null;
|
int? userid = Context.User.UserId();
|
||||||
if (Context.User.HasClaim(item => item.Type == ClaimTypes.NameIdentifier))
|
userid = (userid == -1) ? null : userid;
|
||||||
{
|
|
||||||
userid = int.Parse(Context.User.Claims.First(item => item.Type == ClaimTypes.NameIdentifier).Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if cookie already exists
|
// check if cookie already exists
|
||||||
Visitor visitor = null;
|
Visitor visitor = null;
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
|
using Oqtane.Models;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
|
|
||||||
namespace Oqtane.Extensions
|
namespace Oqtane.Extensions
|
||||||
{
|
{
|
||||||
public static class ClaimsPrincipalExtensions
|
public static class ClaimsPrincipalExtensions
|
||||||
{
|
{
|
||||||
|
// extension methods cannot be properties - the methods below must include a () suffix when referenced
|
||||||
|
|
||||||
public static string Username(this ClaimsPrincipal claimsPrincipal)
|
public static string Username(this ClaimsPrincipal claimsPrincipal)
|
||||||
{
|
{
|
||||||
if (claimsPrincipal.HasClaim(item => item.Type == ClaimTypes.Name))
|
if (claimsPrincipal.HasClaim(item => item.Type == ClaimTypes.Name))
|
||||||
|
|
|
@ -84,7 +84,7 @@ namespace Oqtane.Services
|
||||||
}
|
}
|
||||||
else // cache by user
|
else // cache by user
|
||||||
{
|
{
|
||||||
return await _cache.GetOrCreateAsync($"site:{_accessor.HttpContext.GetAlias().SiteKey}:{_accessor.HttpContext.User.UserId}", async entry =>
|
return await _cache.GetOrCreateAsync($"site:{_accessor.HttpContext.GetAlias().SiteKey}:{_accessor.HttpContext.User.UserId()}", async entry =>
|
||||||
{
|
{
|
||||||
entry.SlidingExpiration = TimeSpan.FromMinutes(30);
|
entry.SlidingExpiration = TimeSpan.FromMinutes(30);
|
||||||
return await GetSite(siteId);
|
return await GetSite(siteId);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user