asp.net-mvc - 在 C# MVC 中捕获所有插入更新事件
问题描述
我正在为我的应用程序使用 asp.net mvc、entitiy 框架和 sql db。我想为 mvc 应用程序中的所有插入更新删除事件创建一种方法,如过滤器作为事件侦听器。对此有什么建议吗?
提前致谢
解决方案
您可以创建一个自定义过滤器并用它装饰您想要的操作或控制器,如下所示:
public class CustomFilter : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
//In case you need it to log which one has been accessed for example
Controller controller = filterContext.Controller as Controller;
//Do your code...
//Continue to the action
base.OnActionExecuting(filterContext);
}
}
推荐阅读
- javascript - URL API 是否需要 encodeURI 作为路径名?
- python - 用于测试的补丁库函数
- queue - ActiveMQ 队列:选择器和独占消费者
- laravel - Laravel 查询构建器:CONCAT 和 JOIN
- swift - Realm Swift - 将结果数组转换为 Ints 数组
- flask - Zappa 如何在 Amazon Lambda 上部署多个烧瓶应用程序?
- firebase - Firebase BigQuery 迁移 bash 错误
- mysql - 当列是复合键的一部分时不使用索引
- sapui5 - 基于SAPUI5中html元素的点击事件执行功能
- node.js - 为什么我应该在 Actions on Google Nodejs 客户端库中使用 dialogflow() 而不是 actionsdk()