Get userId more easily - also changed the default to -1 just in case we can't determine the Id (at least then changes won't be "blamed" on user 0

This commit is contained in:
Sebastiaan Janssen
2017-04-30 10:15:53 +02:00
parent 04a09bd4d6
commit b72c8ef953

View File

@@ -1,4 +1,5 @@
using System;
using System.Threading;
using System.Web;
using Umbraco.Core.Security;
@@ -43,11 +44,8 @@ namespace Umbraco.Core.Auditing
/// <returns></returns>
protected int GetCurrentRequestBackofficeUserId()
{
var userId = 0;
if (HttpContext.Current == null) return userId;
var owinContext = HttpContext.Current.GetOwinContext();
if (owinContext == null) return userId;
var backOfficeIdentity = owinContext.Authentication.User.GetUmbracoIdentity();
var userId = -1;
var backOfficeIdentity = Thread.CurrentPrincipal.GetUmbracoIdentity();
if (backOfficeIdentity != null)
int.TryParse(backOfficeIdentity.Id.ToString(), out userId);
return userId;