似乎无法覆盖 DefaultControllerFactory 中的 CreateController

发布于 2024-10-07 07:54:53 字数 1380 浏览 0 评论 0原文

我正在尝试使用这个很棒的教程将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无人问我粥可暖 2024-10-14 07:54:53

好吧,经过更多研究,我从这个链接发现了这个问题

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.

夢归不見 2024-10-14 07:54:53

我能够成功构建:

  1. 创建了一个新的空 ASP.NET MVC 2 项目
  2. 从教程中,复制了 HandleErrorWithELMAHAttribute 类的代码。
  3. 复制 ErrorHandlingActionInvoker 类的代码。
  4. 复制 ErrorHandlingControllerFactory 类的代码。
  5. 添加了必要的 using 语句和对 ELMAH 的引用。

然后,为了检查,我用您问题中的代码替换了 ErrorHandlingControllerFactory 的原始代码,并且编译也没有错误。

我能够通过添加一个名为 DefaultControllerFactory 的类来获得该错误,以便 ErrorHandlingControllerFactory 将从该类继承。这似乎不太可能,但您可能想确保您从正确的类继承。

I was able to build successfully:

  1. Created a new Empty ASP.NET MVC 2 project
  2. From the tutorial, copied in the code for the HandleErrorWithELMAHAttribute class.
  3. Copied the code for the ErrorHandlingActionInvoker class.
  4. Copied the code for the ErrorHandlingControllerFactory class.
  5. Added necessary 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 that ErrorHandlingControllerFactory would be inheriting from that. It seems unlikely, but you may want to make sure you are inheriting from the correct class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文