4

I want default page of the site to be Login.cshtml. I get the Exception:

Error: The view 'LogIn' or its master was not found or no view engine supports the searched locations. The following locations were searched:

I have 2 areas. Structure is shown below.

enter image description here

My routeconfig is shown below.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace Portal.Web
{
public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "LogIn", id =   UrlParameter.Optional },
            namespaces: new[] { "Portal.Web.Areas.Management" }
        );
    }
    }

}

My global.asax.cs is shown below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;

namespace Portal.Web
{
// Note: For instructions on enabling IIS6 or IIS7 classic mode, 
// visit http://go.microsoft.com/?LinkId=9394801
public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
    }
}
}

`Have you any advice?

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
ftdeveloper
  • 1,053
  • 3
  • 26
  • 50

4 Answers4

7

You forgot some stuff

Recap:

ManagementAreaRegistration.cs

public class ManagementAreaRegistration : AreaRegistration
{
    public override string AreaName
    {
        get
        {
            return "Management";
        }
    }

    public override void RegisterArea(AreaRegistrationContext context)
    {
        context.MapRoute(
            "Management_default",
            "Management/{controller}/{action}/{id}",
          new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }
}

RouteConfig.cs

public static void RegisterRoutes(RouteCollection routes)
{
    routes.MapRoute(
        "Default" // Route name
        , "{controller}/{action}/{id}" // URL with parameters
        , new { area = "management", controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        , new[] { "Portal.Web.Areas.Management.Controllers" } // Namespace of controllers in root area
    );
}   

You set Portal.Web.Areas.Management when it should be Portal.Web.Areas.Management.Controllers also it is missing the default area: area = "management"

Robert Hoffmann
  • 2,366
  • 19
  • 29
1

It looks as though you need to change your namespace on the MapRoute from:

Portal.Web.Areas.Management

To:

Portal.Web.Areas.Management.Controllers
Adrian Thompson Phillips
  • 6,893
  • 6
  • 38
  • 69
-1

Clear out your bin folder and rebuild. There is a chance there is an old dll set up with the old routing. This worked for me for one route at least.

Stuart Dobson
  • 3,001
  • 4
  • 35
  • 37
-5

I followed instruction in this post. And problem is resolved. Visit ASP.NET MVC Default URL View

Thank you all.

Community
  • 1
  • 1
ftdeveloper
  • 1,053
  • 3
  • 26
  • 50
  • There is no definitive answer at that url. what did you finally do ? Change ``defaults: new { controller = "Home", action = "LogIn", id = UrlParameter.Optional }`` to ``defaults: new { area = "management", controller = "Home", action = "LogIn", id = UrlParameter.Optional }`` ? – Robert Hoffmann Jul 17 '13 at 10:30
  • Without any link to a direct solution this is not worth much to anyone. – Syska Jan 04 '14 at 22:09
  • I had the same issue and I solved my problem resolving the namespace of my web application. I move my controllers from no area to Admin Area and didn't work, when i adjust the namespace of all class it worked – renefc3 Jul 01 '14 at 11:38
  • @renefc3 Why did the namespace have to be changed? Maybe you can help me here -> https://stackoverflow.com/questions/25450549/want-to-understand-process-for-troubleshooting-asp-net-mvc-routing-failure – Howiecamp Aug 25 '14 at 05:05