创建单独的模型和控制器项目后,我得到“找不到合适的方法来覆盖”在我的初始化方法声明中
这让我发疯...我正在将我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此错误消息表明您的 AccountController 类不是从 MVC 的 Controller 基类派生的。
this error message suggests that your AccountController class isn't being derived from MVC's Controller base class.
事实证明我缺少的是对 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.