Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在基本控制器中记录所有 ModelState 错误以供参考。我考虑过覆盖 OnActionExecuting,但我不确定这是否是完成该日志记录的正确位置。我的想法是让操作不受该日志记录代码的影响。这是覆盖正确的地方还是有更好的地方?
你有没有想过把它作为一个属性来做。
您可以装饰您感兴趣的操作,并让属性覆盖那里的 onactionexecuting 并执行您需要的日志记录,而不是覆盖基本控制器的每个 onactionexecuting。
您可能会发现这比覆盖整个控制器更合适。