【发布时间】:2016-03-27 21:10:17
【问题描述】:
我正在使用带区域的路线属性。
我的路线配置是:
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/comment 或mysite.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/content 或 mysite.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)galleryController 视图的一些代码! 我很困惑。
我再次强调这只是发生在主机和我的本地系统上,一切都是正确的!
还需要注意的是,这个错误是在今天又一个错误之后发生的,昨天在我的主机上一切都得到了纠正,这个错误直到昨天才出现!
【问题讨论】:
-
你能显示你从 /cms/comment 方法返回的视图吗?
-
为 /cms/comment 返回此视图
~/Areas/CMS/Views/Comment/Index.cshtml,但 /cms/category 有相同的错误 -
为什么你在
RouteConfig.cs中写了Area路由?在您的 CMSArea中应该有一个名为CMSAreaRegistration.cs的文件。 -
我在一篇文章中发现我应该删除
CMSAreaRegistration.cs并在RouteConfig.cs中写入区域路线。昨天一切都是正确的,但今天不是,这个错误只是发生在主机上,在我的本地系统中是正确的!
标签: asp.net asp.net-mvc asp.net-mvc-4 url-rewriting routeattribute