简体   繁体   English

如何防止子类派生自框架基类

[英]How to prevent subclass deriving from framework base class

Writing MVC application and found this technique to be useful: http://forums.asp.net/post/4960505.aspx which basically puts a class-in-the-middle that overrides an event handler method for execution when any correctly derived Controller subclass Action is requested. 编写MVC应用程序并发现此技术很有用: http : //forums.asp.net/post/4960505.aspx ,该方法基本上放置了一个中间类,该中间类将覆盖事件处理程序方法以在任何正确派生的Controller时执行子类请求动作。

Is there a way I can force all not yet written Controllers in the project/solution to derive from the intended subclass-in-the-middle and/or to not be able to derive from the framework base class? 有没有一种方法可以强制项目/解决方案中所有尚未编写的Controller从预期的中间子类派生和/或不能从框架基类派生?

Instead of using a custom base type for every controller, could you accomplish your goal by using a Global ActionFilter? 除了使用每个控制器的自定义基本类型,您还可以使用Global ActionFilter来实现目标吗?

Examples: 例子:

http://weblogs.asp.net/gunnarpeipman/archive/2010/08/15/asp-net-mvc-3-global-action-filters.aspx http://weblogs.asp.net/gunnarpeipman/archive/2010/08/15/asp-net-mvc-3-global-action-filters.aspx

http://haacked.com/archive/2011/04/25/conditional-filters.aspx http://haacked.com/archive/2011/04/25/conditional-filters.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM