asp.net mvc 控制器工厂
我想实现这样的目标:
我想审核所有参与向视图文件提供 http 请求的控制器。
我想审核该控制器上的每个方法并将此信息写入平面文件(滚动记录器??)。
审核日志应包含:
经过身份验证的用户
信息、调用的方法
、方法参数
、时间戳
。
我意识到这需要实现我自己的控制器工厂来执行类似的操作:
//policy injection call that is set up to log all the methods, called on the
//controller.
var myController = ControllerCustomerFactory<FlatRollingLogger>.Create();
下一步我应该做什么,我应该将自定义创建的控制器注入其他地方还是工厂将跟踪需要实例化的控制器?
我在想 Microsoft Ent Lib 策略注入,因为它已经在我们公司用于其他审计目的了?
还有其他更好的想法来处理这个问题吗?
谢谢
I would like to achieve something to this extent:
I want to audit all of my controllers participating in serving http requests to the view files.
I would like to audit each and every method on that controller and write this information to the flat file (rolling logger??).
The audit log should contain:
authenticated user
info,method called
,method parameters
,time stamp
.
I realize that this would require implementing my own controller factory to do something like this:
//policy injection call that is set up to log all the methods, called on the
//controller.
var myController = ControllerCustomerFactory<FlatRollingLogger>.Create();
what should I do next, should I inject the custom created controller somewhere else or the factory will keep track on which controller needs to be instantiated?
I was thinking Microsoft Ent Lib Policy Injection as it has been done for other auditing purposes in our company?
Any other better ideas to handle this?
merci
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,您不需要自己的工厂控制器,只需创建一个全局操作过滤器即可。 MVC 具有很强的可扩展性。
http:// /weblogs.asp.net/gunnarpeipman/archive/2010/08/15/asp-net-mvc-3-global-action-filters.aspx
No, you don't need your own factory controller, just create a global action filter. MVC is very extensible.
http://weblogs.asp.net/gunnarpeipman/archive/2010/08/15/asp-net-mvc-3-global-action-filters.aspx
您可能需要考虑使用 PostSharp 等框架的面向方面的方法。您可以使用日志框架(例如 log4net )来执行实际日志记录。
You might want to consider an aspect oriented approach using a framework such as PostSharp. You can use a logging framework such as log4net to perform the actual logging.