简体   繁体   English

无法找到该资源。 要求的网址:/ Area / Controller / undefined

[英]The resource cannot be found. Requested URL: /Area/Controller/undefined

I am getting the error shown below. 我收到下面显示的错误。 I am getting this error way before my code execution reaches return View() or return redirect to action. 在我的代码执行到达return View()或return redirect to action之前,我得到了这种错误方式。

I have areas set up. 我设置了区域。 I am also posting the area registration section to check if anything is wrong there. 我还将发布区域注册部分,以检查那里是否有任何问题。 I have checked spellings of folders. 我检查了文件夹的拼写。 Everything runs fine until there is any section that gets data from the database via Entity Framework. 一切运行良好,直到有任何部分可以通过Entity Framework从数据库获取数据为止。 I am really confused as to what is causing this problem. 我对造成此问题的原因感到非常困惑。

Server Error in '/' Application. “ /”应用程序中的服务器错误。

The resource cannot be found. 无法找到该资源。

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. 说明:HTTP404。您正在寻找的资源(或其依赖项之一)可能已被删除,名称更改或暂时不可用。 Please review the following URL and make sure that it is spelled correctly. 请查看以下网址,并确保其拼写正确。

Requested URL: /Admin/Home/undefined 要求的网址:/ Admin / Home / undefined

Version Information: Microsoft .NET Framework Version:4.0.30319; 版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET >Version:4.0.30319.18408 ASP.NET>版本:4.0.30319.18408

Home Controller under Area 区域下的家庭控制器

[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" }
        );
    }
}

Please let me know if there is anything else that I need to share in order to make the problem more clear. 请让我知道是否还有其他需要分享的内容,以便使问题更明确。

Change your default route in global asax because it is looking for "Index" method in your "Home" controller which doesn't exists. 在全局asax中更改默认路由,因为它正在不存在的“ Home”控制器中寻找“ Index”方法。

change your action property from 从更改您的动作属性

 new { controller = "Home", action = "Index", id = UrlParameter.Optional },

to this if "Login" is your default page 如果“登录”是您的默认页面,请执行此操作

 new { controller = "Home", action = "Login", id = UrlParameter.Optional },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM