fix issue referencing ClaimsPrincipal UserId extension method
This commit is contained in:
parent
38c468a204
commit
2dec3195ac
|
@ -326,11 +326,8 @@
|
|||
// get other request attributes
|
||||
string url = Context.Request.GetEncodedUrl();
|
||||
string referrer = (Context.Request.Headers[HeaderNames.Referer] != StringValues.Empty) ? Context.Request.Headers[HeaderNames.Referer] : "";
|
||||
int? userid = null;
|
||||
if (Context.User.HasClaim(item => item.Type == ClaimTypes.NameIdentifier))
|
||||
{
|
||||
userid = int.Parse(Context.User.Claims.First(item => item.Type == ClaimTypes.NameIdentifier).Value);
|
||||
}
|
||||
int? userid = Context.User.UserId();
|
||||
userid = (userid == -1) ? null : userid;
|
||||
|
||||
// check if cookie already exists
|
||||
Visitor visitor = null;
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Extensions
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (claimsPrincipal.HasClaim(item => item.Type == ClaimTypes.Name))
|
||||
|
|
|
@ -84,7 +84,7 @@ namespace Oqtane.Services
|
|||
}
|
||||
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);
|
||||
return await GetSite(siteId);
|
||||
|
|
Loading…
Reference in New Issue
Block a user