How to simulate ActionFilter attribute in Asp.net web form

In MVC, a user can use an action filter as follows:

[Log]
ActionResult Home()
{
     return View();
}

Now I'm going to find the equivalent of ActionFilter in an asp.net web form. How can I simulate the ones mentioned above for an asp.net web form and apply them to event handlers?

[Log]
protect void btnSearch_Click(object sender, EventArgs e)
{
     //Do some operations here
}

Update:

To clarify my question (since the comment says my question is a bit ambiguous), I want to write down the beginning of the method and the end of the method. In Mvc, I can create an Action Filter as follows:

public class LogAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        //Logging start of method.
    }

    public override void OnActionExecuted(ActionExecutedContext filterContext)
    {
        //Logging end of method.
    }
}
+4
source share

Source: https://habr.com/ru/post/1532330/


All Articles