1

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.