How to pass parameter "IsAuthenticated" to actionfilter?

1

I'm trying somehow to pass parameter to actionfilter .

Please follow the code:

Controller:

[LogActionFilter(IsAuthenticated = Request.IsAuthenticated)]
//Tentativa 1 System.Web.HttpContext.Current.Request.IsAuthenticated  

ActionFilter:

public class LogActionFilter : ActionFilterAttribute
{
    public string IsAuthenticated { get; set; }
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    { 
      etc...

I get this error:

  

An object reference is required for the non-static field, method, or   property 'Controller.HttpContext'

    
asked by anonymous 07.03.2017 / 19:33

1 answer

1

Matheus, an alternative for you would be to not pass Request.IsAuthenticated as a parameter to your LogActionFilter and instead use IsAuthenticated inside your OnActionExecuted , being as follows:

public override void OnActionExecuted(ActionExecutedContext filterContext)
{
    if (filterContext.RequestContext.HttpContext.Request.IsAuthenticated)
        Debugger.Log(0, "", "");
    base.OnActionExecuted(filterContext);
}
    
07.03.2017 / 21:09