[英]Asp.net Mvc areas routing issue
I want default page of the site to be Login.cshtml. 我希望网站的默认页面为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. 我有2个区域。 Structure is shown below.
结构如下所示。
My routeconfig is shown below. 我的routeconfig如下所示。
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: 我的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);
}
}
}
`Have you any advice? 你有什么建议吗?
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"
您可以设置
Portal.Web.Areas.Management
当它应该是Portal.Web.Areas.Management.Controllers
也是它缺少默认面积: area = "management"
It looks as though you need to change your namespace on the MapRoute
from: 似乎您需要从以下位置更改
MapRoute
上的名称空间:
Portal.Web.Areas.Management
To: 至:
Portal.Web.Areas.Management.Controllers
Clear out your bin folder and rebuild. 清除您的bin文件夹并重建。 There is a chance there is an old dll set up with the old routing.
有机会使用旧的路由设置了旧的dll。 This worked for me for one route at least.
这至少对我有用。
I followed instruction in this post. 我按照这篇文章中的说明进行操作。 And problem is resolved.
问题就解决了。 Visit ASP.NET MVC Default URL View
访问ASP.NET MVC默认URL视图
Thank you all. 谢谢你们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.