I tried to access the Identity current User in my abstract base controller constructor to use the link to display user in View if It signed in.
So, I got User
property is null
. Everybody advice use filter and return User via ViewData. Example here: "Why is User (as in User.Identity.Name) null in my abstract base controller?"
I tried do somethink like this, but face with the problem: AuthorizationContext
has no member Controller
!
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public class UserAuthorizationAttribute : Attribute, IAuthorizationFilter
{
public void OnAuthorization(Microsoft.AspNet.Mvc.Filters.AuthorizationContext filterContext)
{
filterContext.Controller.ViewData["IdentityUser"] = filterContext.HttpContext.User;
}
}
So, I have two questions:
You could try using an Action Filter as opposed to an Authorisation Filter. These are processed later in the pipeline, and have access to the user.