1

我正在使用区域的路线属性。

我的路线配置是:

public static void RegisterRoutes(RouteCollection routes)
{
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapMvcAttributeRoutes();

        routes.MapRoute(
            "Default",
            "{controller}/{action}/{id}",
            new { controller = "Home", action = "Index", id = UrlParameter.Optional },
            new[] { "Peacock.Controllers" }
        );

        routes.MapRoute(
            "CMS",
            "CMS/{controller}/{action}/{id}",
            new { controller = "Home", action = "Index", id = UrlParameter.Optional },
            new[] { "CMS.Controllers" }
        );
}

在我的本地一切都是正确的!今天,当我发布我的项目并将其上传到我的主机时,我遇到了两种类型的错误。

如果我请求 Default MapRoute 的 url,mysite.com/Contents/1060一切都是正确的!但是当我请求我所在地区的网址时,我遇到了两种错误!

1)一些请求喜欢mysite.com/cms/commentmysite.com/cms/category有这个错误:

The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Areas/CMS/Views/ContentCategory/Index.aspx
~/Areas/CMS/Views/ContentCategory/Index.ascx
~/Areas/CMS/Views/Shared/Index.aspx
~/Areas/CMS/Views/Shared/Index.ascx
~/Views/ContentCategory/Index.aspx
~/Views/ContentCategory/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Areas/CMS/Views/ContentCategory/Index.cshtml
~/Areas/CMS/Views/ContentCategory/Index.vbhtml
~/Areas/CMS/Views/Shared/Index.cshtml
~/Areas/CMS/Views/Shared/Index.vbhtml
~/Views/ContentCategory/Index.cshtml
~/Views/ContentCategory/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

~/Areas/CMS/Views/ContentCategory/Index.cshtml存在于我的主机上!

2)其他一些请求喜欢mysite.com/cms/contentmysite.com/cms/gallery有这个错误:

 The partial view '~/Content/templates///views/Gallery/index.cshtml' was not found or no view engine supports the searched locations. The following locations were searched:
 ~/Content/templates///views/Gallery/index.cshtml
 Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The partial view '~/Content/templates///views/Gallery/index.cshtml' was not found or no view engine supports the searched locations. The following locations were searched:
~/Content/templates///views/Gallery/index.cshtml

Source Error:


Line 3:      string view = "~/Content/templates/" + ViewBag.website + "/" + ViewBag.lang + "/views/Gallery/index.cshtml";
Line 4:      Html.RenderPartial(view);
Line 5:  }
Line 6:  

此错误的“源错误”显示了画廊控制器的默认项目(不是 cms)视图的一些代码!我感到很困惑。

我再次强调这只是发生在主机和我的本地系统上,一切都是正确的!

还应该注意的是,这个错误发生在今天又一个错误之后,昨天在我的主机上一切都得到了纠正,这个错误直到昨天才出现!

4

2 回答 2

1

我有同样的问题!我错误地将我的“区域”文件夹重命名为“区域”并遇到此错误!

错误 2:当您在默认项目中有一个与请求的控制器同名的控制器时发生!

错误1:当您在默认项目中没有与请求的控制器同名的控制器时发生!

祝你好运。

于 2015-12-22T17:00:14.387 回答
0

我不知道这是否是您唯一的问题,但您的路线列出的顺序错误。

按照您配置路由的方式,任何以 2 或 3 个分段 URL 开头的 URLCMS都将匹配Default路由而不是CMS路由。由于使用了错误的命名空间(因此调用了错误的控制器),因此可能无法找到您的视图。要解决此问题,您应该CMSDefault.

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapMvcAttributeRoutes();

    routes.MapRoute(
        "CMS",
        "CMS/{controller}/{action}/{id}",
        new { controller = "Home", action = "Index", id = UrlParameter.Optional },
        new[] { "CMS.Controllers" }
    );

    routes.MapRoute(
        "Default",
        "{controller}/{action}/{id}",
        new { controller = "Home", action = "Index", id = UrlParameter.Optional },
        new[] { "Peacock.Controllers" }
    );
}

当然,该错误也可能表明您尚未将所有视图完全部署到您的服务器。

于 2015-12-21T18:07:24.610 回答