![](/img/trans.png)
[英]How can I pass the Id from Login method in Account Controller in ASP.Net MVC Entity Framework?
[英]ASP.NET MVC [Authorize] from controller in area can't find Account/Login ActionResult in root folder
我正在嘗試為我的MVC網站設置管理員登錄名。 我有一個名為Admin的區域,其中有一個名為ControlPanel
的控制器。 我已經將[Authorize]
屬性放在ControlPanel
Controller聲明上方。 當我調用該控制器的索引時,出現錯誤提示
它找不到帳戶/登錄資源。
AccountController
存儲在根目錄的“ Controllers”文件夾中。 該視圖位於根目錄的“視圖”文件夾中。
我的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 }
);
}
}
我的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 }
);
}
}
提前致謝
您的路線似乎混亂了。 請嘗試以下代碼來配置您的路由。
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.