创建单独的模型和控制器项目后,我得到“找不到合适的方法来覆盖”在我的初始化方法声明中

发布于 2024-10-13 04:51:19 字数 826 浏览 1 评论 0原文

这让我发疯...我正在将我的 MVC 应用程序重新组织为一个模型项目和一个控制器项目,然后将主应用程序作为一个项目。所以,到目前为止,一切都运行良好,除了......

每当我去“重建”我的控制器项目时,我都会收到此错误:

Controllers.AccountController.Initialize(System.Web.Routing.RequestContext)':找不到合适的方法来覆盖。

请记住,AccountController.cs 是由 Visual Studio 自动放置在我的应用程序中的,当控制器位于我的主项目中时,这一切都工作正常。我认为这可能与 AccountController.cs 文件引用的 ASPNETDB.MDF 文件有关,以便在用户登录时对用户进行身份验证,因为该数据库保留在我的主项目中,并且没有遵循 Controllers 项目。对此有何想法??

这是我的 AccountController 上的初始化方法:

        protected override void Initialize(RequestContext requestContext)
    {
        if (FormsService == null) { FormsService = new FormsAuthenticationService(); }
        if (MembershipService == null) { MembershipService = new AccountMembershipService(); }

        base.Initialize(requestContext);
    }

请帮忙!!!提前致谢!!

This is driving me insane... I am reorganizing my MVC app into a Models project and a Controllers project, and then the main application as a project. So, everything is working good so far except...

Whenever I go to "Rebuild" my controllers project, I get this error:

Controllers.AccountController.Initialize(System.Web.Routing.RequestContext)': no suitable method found to override.

Keep in mind that AccountController.cs was automatically placed in my application by Visual Studio, and this was all working fine when the Controllers were within my main project. I think it might have to do with the ASPNETDB.MDF file that this AccountController.cs file references to authenticate users as they log in, since this database stayed within my main project and didn't follow the Controllers project. Thoughts on that??

Here's the Initialize method on my AccountController:

        protected override void Initialize(RequestContext requestContext)
    {
        if (FormsService == null) { FormsService = new FormsAuthenticationService(); }
        if (MembershipService == null) { MembershipService = new AccountMembershipService(); }

        base.Initialize(requestContext);
    }

PLEASE HELP!!! Thanks in advance!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

草莓酥 2024-10-20 04:51:19

此错误消息表明您的 AccountController 类不是从 MVC 的 Controller 基类派生的。

this error message suggests that your AccountController class isn't being derived from MVC's Controller base class.

昨迟人 2024-10-20 04:51:19

事实证明我缺少的是对 System.Web.Routing 的引用。我使用了 System.Web.Routing,并且它没有标记为“红色”(意思是,它找不到它),所以我只是假设它在那里。所以这解决了问题。

It turns out what I was missing was a reference to System.Web.Routing. I had using System.Web.Routing, and it wasn't marked "red" (meaning, it couldn't find it), so I just assumed it was there. So this fixed the problem.

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