How to pass "Isauthenticated" parameter to actionfilter?

Asked

Viewed 87 times

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 that mistake:

An Object Reference is required for the non-static field, method, or Property 'Controller.Httpcontext'

1 answer

1


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

public override void OnActionExecuted(ActionExecutedContext filterContext)
{
    if (filterContext.RequestContext.HttpContext.Request.IsAuthenticated)
        Debugger.Log(0, "", "");
    base.OnActionExecuted(filterContext);
}
  • Solved problem here, thanks @Pablo Tondolo de Vargas

Browser other questions tagged

You are not signed in. Login or sign up in order to post.