1

I am using route attributes with areas.

My route config is :

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" }
        );
}

On my local every things is correct! Today when I published my project and upload its on my host I faced with tow types of errors.

If I request url of Default MapRoute like mysite.com/Contents/1060 everything is correct! But when I request a url of my area, I faced tow type of errors!

1) some requests like mysite.com/cms/comment or mysite.com/cms/category has this error:

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.

but ~/Areas/CMS/Views/ContentCategory/Index.cshtml is exist on my host!

2) some other requests like mysite.com/cms/content or mysite.com/cms/gallery has this error:

 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:  

The 'Source Error' of this error show some code of my default project(not cms) view of galleryController! I am so confused.

I emphasize again this just happen on host and on my local system every things is correct!

It should also be noted that this error happen today after another error, yesterday on my host everything was corrected and this error was not until yesterday!

Mostafa
  • 51
  • 7
  • Can you show what view you are returning from /cms/comment method ? – Shyju Dec 21 '15 at 18:05
  • return this view `~/Areas/CMS/Views/Comment/Index.cshtml` for /cms/comment but has same error for /cms/category – Mostafa Dec 21 '15 at 18:10
  • Why you've written `Area` route in `RouteConfig.cs`? There should be a file named `CMSAreaRegistration.cs` in your CMS `Area`. – Ibrahim Khan Dec 21 '15 at 19:29
  • I found on a articel that I should remove `CMSAreaRegistration.cs` and written Area route in `RouteConfig.cs`. Yesterday every thing was correct but today is not, and this error just happen on host and in my local system is correct! – Mostafa Dec 22 '15 at 02:55

2 Answers2

1

I have same problem! I renamed my 'Areas' folder with 'Area' by mistake and faced with this error!

error 2 : happen when you have a controller with the same name of the requested controller in Default project!

error 1 : happen when you dont have a controller with the same name of the requested controller in Default project!

Good luck.

Mostafa Azarirad
  • 629
  • 1
  • 6
  • 27
0

I don't know if this is your only problem, but your routes are listed in the wrong order.

The way you have your routing configured, any 2 or 3 segment URLs that begin with CMS will match the Default route and not the CMS route. It is possible that because of this issue your views aren't being found because the wrong namespace is being used (and thus wrong controller is being called). To fix this, you should register the CMS route before Default.

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" }
    );
}

Of course, the error may also indicate that you haven't fully deployed all of your views to your server.

NightOwl888
  • 55,572
  • 24
  • 139
  • 212