You need to enable JavaScript to run this app. '/'应用程序服务器错误:/Students/Login链接跳转失败如何修复?
优惠活动
大模型
产品
解决方案
定价
更多

'/'应用程序服务器错误:/Students/Login链接跳转失败如何修复?

问题修复方案

你遇到的是ASP.NET MVC中ActionLink跳转异常问题,可按以下步骤排查修复:

  • 第一步:检查StudentsController中是否存在对应GET类型的Login Action方法
    点击链接触发的是GET请求,你需要在StudentsController.cs中添加如下无权限限制的Action代码:
    // 必须添加AllowAnonymous特性,否则未登录用户会被权限拦截
    [AllowAnonymous]
    public ActionResult Login()
    {
        return View();
    }
    // 若有登录提交逻辑,可补充对应POST类型的Action
    [HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]
    public ActionResult Login(LoginViewModel model)
    {
        // 此处编写登录校验逻辑
        if (ModelState.IsValid)
        {
            // 登录验证成功后的跳转逻辑
            return RedirectToAction("Index", "Home");
        }
        return View(model);
    }
    
  • 第二步:确认路由配置规则
    打开App_Start/RouteConfig.cs,确认默认路由规则存在,且优先级放在所有自定义路由之后:
    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );
    
  • 第三步:检查视图文件存放路径
    确认Login.cshtml文件存放路径为~/Views/Students/Login.cshtml,和你提供的截图路径一致即可。
  • 第四步:排查全局权限拦截配置
    如果你在全局过滤器中配置了[Authorize],或是StudentsController类上添加了[Authorize]特性,未加[AllowAnonymous]的Login Action会被直接拦截重定向,按第一步给Login Action加上对应特性即可解决。
  • 额外校验:确认Action名称、视图名称和ActionLink中指定的"Login"拼写完全匹配,ASP.NET MVC路由不区分大小写但拼写必须完全一致。

内容的提问来源于stack exchange,提问作者Lord Unknown

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.19 16:15:08