C# Asp.net Mvc区域路由问题

C# Asp.net Mvc区域路由问题,c#,asp.net-mvc,asp.net-mvc-areas,C#,Asp.net Mvc,Asp.net Mvc Areas,我希望该站点的默认页面为Login.cshtml。我得到一个例外: 错误:未找到视图“登录”或其主视图,或者没有视图引擎支持搜索的位置。搜索了以下地点: 我有两个领域。结构如下所示 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Routing; namespace Portal.Web { pu

我希望该站点的默认页面为Login.cshtml。我得到一个例外:

错误:未找到视图“登录”或其主视图,或者没有视图引擎支持搜索的位置。搜索了以下地点:

我有两个领域。结构如下所示

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

}

我的路线图如下所示

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如下所示:

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

`您有什么建议吗?

看起来您需要从以下位置更改
MapRoute
上的命名空间:

Portal.Web.Areas.Management
致:

你忘了一些东西

概述:

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 }
        );
    }
}
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
    );
}   
RouteConfig.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 }
        );
    }
}
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
    );
}   

您将
Portal.Web.Areas.Management
设置为
Portal.Web.Areas.Management.Controllers
并且它缺少默认区域:
area=“Management”
我遵循了本文中的说明。问题解决了。拜访


谢谢大家

清除bin文件夹并重建。可能存在使用旧路由设置的旧dll。至少有一条路线对我有效

在这个url上没有明确的答案。你最后做了什么?更改
默认值:新建{controller=“Home”,action=“LogIn”,id=UrlParameter.Optional}
默认值:新建{area=“management”,controller=“Home”,action=“LogIn”,id=UrlParameter.Optional}
?如果没有指向直接解决方案的任何链接,这对任何人都没有多大价值。我也遇到了同样的问题,我解决了解决web应用程序名称空间的问题。当我调整它的所有类的名称空间时,我将我的控制器从无区域移动到管理区域,并且没有工作worked@renefc3为什么必须更改名称空间?也许你可以在这里帮助我->