MVC3 - 找不到资源

发布于 2024-12-28 22:07:13 字数 1242 浏览 0 评论 0原文

我遇到了一个我无法理解的奇怪问题。我的一个控制器已停止工作,但如果我重命名它,它就可以正常工作。我没有任何特殊的路由围绕这个控制器,它只是使用我的默认路由。

具体来说,我有一个名为“Kangaroo”的控制器。在浏览器中,如果我转到 {server}/Kangaroo,则会收到“找不到资源”消息。但是,如果我转到 {server}/Kangaroo/Index,那么我的页面会正常加载。我在其他任何控制器上都没有这个问题,只有这个。如果我将控制器(和我的视图文件夹)重命名为“Kangaroo2”,那么它就可以正常工作。

这是我的路线:

public class RouteDefinitions {
    public static void AddRoutes(RouteCollection routes) {
        routes.Ignore("{resource}.axd/{*pathInfo}");
        routes.MapRoute("Resources", 
                        "cache/{action}/{key}/{version}/{type}", 
                        new { controller = "Cache", 
                              action = "CacheContent", 
                              key = "", 
                              version = "", 
                              type = "" });
        routes.MapRoute("Default", // Route name
                        "{controller}/{action}/{id}", // URL with parameters
                        new {
                              controller = "Home",
                              action = "Index",
                              id = ""
                             } // Parameter defaults
                       );
    }
}

有人知道这里会发生什么吗?我认为这可能只是视觉工作室的一个奇怪的事情,但重新启动并没有解决问题。

I've come across a bit of a weird problem I can't make sense of. One of my controllers has stopped working, but if I rename it then it works fine. I don't have any special routing wrapped around this controller, it just uses my default.

To give specifics, I have a controller called "Kangaroo". In the browser, if I go to {server}/Kangaroo, then I get the "The Resource cannot be found" message. However, if I go to {server}/Kangaroo/Index, then my page loads as normal. I don't have this problem on any of my other controllers, only this one. If I rename the controller (and my view folder) to "Kangaroo2", then it works perfectly fine.

Here is my route:

public class RouteDefinitions {
    public static void AddRoutes(RouteCollection routes) {
        routes.Ignore("{resource}.axd/{*pathInfo}");
        routes.MapRoute("Resources", 
                        "cache/{action}/{key}/{version}/{type}", 
                        new { controller = "Cache", 
                              action = "CacheContent", 
                              key = "", 
                              version = "", 
                              type = "" });
        routes.MapRoute("Default", // Route name
                        "{controller}/{action}/{id}", // URL with parameters
                        new {
                              controller = "Home",
                              action = "Index",
                              id = ""
                             } // Parameter defaults
                       );
    }
}

Does anyone have an idea of what could be going on here? I thought it might just be a weird visual studio thing, but restarting did not correct the issue.

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

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

发布评论

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

评论(1

素手挽清风 2025-01-04 22:07:13

刚刚弄清楚问题是什么。我的项目中有一个名为“/Kangaroo”的文件夹。我猜它把它当作脚本或其他内容来对待。由于该路径存在,因此它尝试从该路径加载某些内容。

Just figured out what the problem was. There was a folder in my project called "/Kangaroo". I guess it was treating it like a script or other content. Since the path existed it was attempting to load something from the path.

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