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

ASP.NET Core 5.0 MVC Web API集成Google Auth跳转signin-google报404求助

你遇到的404问题由两个配置错误导致:

  • 未在HTTP请求管道中注册身份验证中间件,Google的/signin-google回调请求没有对应逻辑处理,直接进入MVC路由匹配后找不到对应接口返回404
  • 即便补全中间件,也需要保证身份验证中间件执行顺序在授权中间件之前,否则认证逻辑不会生效

修复方案

修改Startup.cs的Configure方法,补全UseAuthentication中间件并调整顺序:

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
        app.UseSwagger();
        app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebApplication3 v1"));
    }

    app.UseHttpsRedirection();
    app.UseStaticFiles();
    app.UseRouting();
    // 新增身份验证中间件,必须放在UseAuthorization之前
    app.UseAuthentication();
    app.UseAuthorization();
    app.UseMvc();
}

另外你提供的launchsettings.json存在语法笔误,WebApplication3 profile的applicationUrl配置缺少左侧引号,修正后为:

"applicationUrl": "https://localhost:5001;http://localhost:5000",

修改完成后重启项目即可正常处理Google登录回调,完成身份验证流程。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 12:54:01