jeudi 16 juillet 2020

Access Attribute data from method

I'm using asp.net core api project and I use a custom ActionFilter attribute to do some authentication validations as below:

public class LoggedInAttribute : ActionFilterAttribute
{
    public Login LoggedInUser { get; private set; }
    public override void OnActionExecuting(ActionExecutingContext con)
    {
        LoggedInUser = //here i get the logged in user(from a http token request header) and load it from database
        if (LoggedInUser == null)
        {
            con.Result = new UnauthorizedResult();
        }
    }
}

Then I placed this attribute on an action in the api controller as below:

    [HttpGet("user/GetAccountInfo")]
    [LoggedIn]
    public AccountInfoDTO GetAccountInfo()
    {
       //Here i want to get the placed [LoggedIn] instance to get it's LoggedInUser value
    }

I need to get the LoggedInUser property inside the method, I've tried some reflection but I get null everytime.





Aucun commentaire:

Enregistrer un commentaire