我正在使用具有區域的路由屬性。當在asp.net主機上發佈時,區域混亂的路由屬性mvc 5
我的路線是配置:
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" }
);
}
在我的本地每一個東西是正確的!今天,當我發佈我的項目並將其上傳到我的主機上時,我遇到了兩種類型的錯誤。
如果我要求默認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:
這個錯誤的「源錯誤」顯示我的默認項目galleryController的(不是CMS)鑑於一些代碼! 我很困惑。
我再次強調這只是在主機和我的本地系統上發生的每件事情都是正確的!
還應該指出,這個錯誤發生在今天又一個錯誤之後,昨天在我的主機上一切都被糾正了,這個錯誤直到昨天才發生!
您可以顯示您從/ cms/comment方法返回的視圖嗎? – Shyju
返回這個視圖'〜/ Areas/CMS/Views/Comment/Index.cshtml' for/cms/comment但是對於/ cms/category有相同的錯誤 – Mostafa
爲什麼你在'RouteConfig.cs'中寫了'Area'路由?你的CMS區域應該有一個名爲'CMSAreaRegistration.cs'的文件。 – Azim