似乎无法覆盖 DefaultControllerFactory 中的 CreateController
我正在尝试使用这个很棒的教程将 Elmah 实现到我的 MVC 应用程序中。
http://dotnetdarren.wordpress.com/2010/ 07/27/logging-on-mvc-part-1/
一切看起来都很好,但是当我构建时,我得到
找不到合适的方法来覆盖
下面是我从示例中直接获取的类
public class ErrorHandlingControllerFactory : DefaultControllerFactory
{
/// <summary>
/// Injects a custom attribute
/// on every action that is invoked by the controller
/// </summary>
/// <param name="requestContext">The request context</param>
/// <param name="controllerName">The name of the controller</param>
/// <returns>An instance of a controller</returns>
public override IController CreateController(
RequestContext requestContext,
string controllerName)
{
var controller =
base.CreateController(requestContext,
controllerName);
var c = controller as Controller;
if (c != null)
{
c.ActionInvoker =
new ErrorHandlingActionInvoker(
new HandleErrorWithELMAHAttribute());
}
return controller;
}
}
I'm trying to implement Elmah into my MVC application using this great tutorial.
http://dotnetdarren.wordpress.com/2010/07/27/logging-on-mvc-part-1/
Everything seems fine, but when I build, I get
no suitable method found to override
Below is the class I took right from the sample
public class ErrorHandlingControllerFactory : DefaultControllerFactory
{
/// <summary>
/// Injects a custom attribute
/// on every action that is invoked by the controller
/// </summary>
/// <param name="requestContext">The request context</param>
/// <param name="controllerName">The name of the controller</param>
/// <returns>An instance of a controller</returns>
public override IController CreateController(
RequestContext requestContext,
string controllerName)
{
var controller =
base.CreateController(requestContext,
controllerName);
var c = controller as Controller;
if (c != null)
{
c.ActionInvoker =
new ErrorHandlingActionInvoker(
new HandleErrorWithELMAHAttribute());
}
return controller;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,经过更多研究,我从这个链接发现了这个问题
http://forums.asp.net /t/1622810.aspx
需要添加对 System.Web.Routing 的引用,因为它位于单独的项目中。
Well, after much more research, I found the issue from this link
http://forums.asp.net/t/1622810.aspx
Needed to add a reference to System.Web.Routing since it was in a seperate project.
我能够成功构建:
HandleErrorWithELMAHAttribute
类的代码。ErrorHandlingActionInvoker
类的代码。ErrorHandlingControllerFactory
类的代码。using
语句和对 ELMAH 的引用。然后,为了检查,我用您问题中的代码替换了
ErrorHandlingControllerFactory
的原始代码,并且编译也没有错误。我能够通过添加一个名为
DefaultControllerFactory
的类来获得该错误,以便ErrorHandlingControllerFactory
将从该类继承。这似乎不太可能,但您可能想确保您从正确的类继承。I was able to build successfully:
HandleErrorWithELMAHAttribute
class.ErrorHandlingActionInvoker
class.ErrorHandlingControllerFactory
class.using
statements and a reference to ELMAH.Then, to check, I replaced the original code for the
ErrorHandlingControllerFactory
with the code from your question, and it also compiled without error.I was able to get that error was by adding a class named
DefaultControllerFactory
so thatErrorHandlingControllerFactory
would be inheriting from that. It seems unlikely, but you may want to make sure you are inheriting from the correct class.