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:
- Is there any way to send data from Filter to the Controller?
- Maybe there is any other way to get not null User?