[英]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.