You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ASP.NET MVC 5中Account/Login页面HTTP 404错误排查

解决ASP.NET MVC访问Account/Login时的404错误

以下是常见的排查与解决方向:

  • 控制器命名与实现检查
    必须确保控制器类名为AccountController,且为public权限并继承自Controller基类,同时包含Login Action方法:

    public class AccountController : Controller
    {
        // 确保该方法为public且存在
        public ActionResult Login()
        {
            return View();
        }
    }
    *MVC路由依赖「控制器名+Controller」的命名约定,不符合则无法匹配请求。*
    
    
  • 视图路径验证
    MVC默认会在~/Views/[控制器名]/目录下查找视图,因此Login.cshtml必须放在~/Views/Account/Login.cshtml路径下。如果视图在~/Account/Login,要么调整视图位置,要么在Action中显式指定视图路径:

    return View("~/Account/Login.cshtml");
    
  • 路由配置核对
    确认RouteConfig.cs中的默认路由规则正确,没有覆盖或拦截Account/Login的请求:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }
    

    若存在自定义路由,需确保其优先级不会导致Account/Login请求被错误路由。

  • Forms认证配置检查
    检查Web.config中的Forms认证节点,loginUrl必须指向正确路径:

    <authentication mode="Forms">
        <forms loginUrl="~/Account/Login" timeout="2880" />
    </authentication>
    

    同时确认<authorization>节点未设置错误规则,避免请求被意外重定向。

  • 编译与服务器配置验证

    • 确保项目无编译错误,AccountController已正确编译到程序集。
    • 若部署到IIS,确认应用程序池的.NET版本与MVC项目版本匹配(如MVC 5对应.NET 4.5+),且IIS已启用ASP.NET模块映射。

内容的提问来源于stack exchange,提问作者Deyvid Rannyere Moraes Costa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 09:23:07