[英]The resource cannot be found. Requested URL: /Area/Controller/undefined
我收到下面顯示的錯誤。 在我的代碼執行到達return View()或return redirect to action之前,我得到了這種錯誤方式。
我設置了區域。 我還將發布區域注冊部分,以檢查那里是否有任何問題。 我檢查了文件夾的拼寫。 一切運行良好,直到有任何部分可以通過Entity Framework從數據庫獲取數據為止。 我對造成此問題的原因感到非常困惑。
“ /”應用程序中的服務器錯誤。
無法找到該資源。
說明:HTTP404。您正在尋找的資源(或其依賴項之一)可能已被刪除,名稱更改或暫時不可用。 請查看以下網址,並確保其拼寫正確。
要求的網址:/ Admin / Home / undefined
版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET>版本:4.0.30319.18408
區域下的家庭控制器
[HttpGet]
[Authorize]
public ActionResult Show()
{
return View();
}
public ActionResult Login()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Login(string rememberMe, string UserName, string Password)
{
AuthenticateUser Authenticate = new AuthenticateUser();
if (Authenticate.isUserAuthentic(UserName, Password))
{
//the error page is rendered here ..
//even before reaching the return View portion or Redirect to action
FormsAuthentication.SetAuthCookie(UserName, false);
return RedirectToAction("Show");
}
else
{
return View();
}
}
DBCONTEXT DB = new DBCONTEXT();
public bool isUserAuthentic(string UserName, string Password)
{
bool Authentic = false;
admin_users User = DB.admin_users.SingleOrDefault(u => u.user_name == UserName);
if (User != null)
{
if (User.user_password == Password)
{
Authentic = true;
}
else
{
Authentic = false;
}
}
return Authentic;
}
public class AdminAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Admin";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { controller = "Home", action = "Show", id = UrlParameter.Optional },
namespaces: new[] { "ProjectName.Areas.Admin.Controllers" }
);
}
}
請讓我知道是否還有其他需要分享的內容,以便使問題更明確。
在全局asax中更改默認路由,因為它正在不存在的“ Home”控制器中尋找“ Index”方法。
從更改您的動作屬性
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
如果“登錄”是您的默認頁面,請執行此操作
new { controller = "Home", action = "Login", id = UrlParameter.Optional },
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.