[英]ASP.NET MVC [Authorize] from controller in area can't find Account/Login ActionResult in root folder
I'm trying to setup admin logins for my MVC site. 我正在尝试为我的MVC网站设置管理员登录名。 I have an area called Admin with a controller called
ControlPanel
. 我有一个名为Admin的区域,其中有一个名为
ControlPanel
的控制器。 I've placed the [Authorize]
attribute above the ControlPanel
Controller declaration. 我已经将
[Authorize]
属性放在ControlPanel
Controller声明上方。 When I make a call to the index of that controller I get an error saying 当我调用该控制器的索引时,出现错误提示
it can't find the Account/Login resource.
它找不到帐户/登录资源。
The AccountController
is stored in the root's 'Controllers' folder. AccountController
存储在根目录的“ Controllers”文件夹中。 The view exists in the root's 'Views' folder. 该视图位于根目录的“视图”文件夹中。
My AdminAreaRegistration
class: 我的
AdminAreaRegistration
类:
public class AdminAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Admin";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Admin_default",
"{area}/{controller}/{action}/{id}",
new { area="Admin", action = "Index", id = UrlParameter.Optional }
);
}
}
My RouteConfig
class: 我的
RouteConfig
类:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{area}/{controller}/{action}/{id}",
defaults: new { area = "", controller = "Startup", action = "Index", id = UrlParameter.Optional }
);
}
}
Thanks in advance 提前致谢
Your route seems to be messed up. 您的路线似乎混乱了。 Try the code below to configure your routing.
请尝试以下代码来配置您的路由。
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { area="Admin", action = "Index", id = UrlParameter.Optional }
);
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new {controller = "Startup", action = "Index", id = UrlParameter.Optional }
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.