小编Phi*_*ier的帖子

无法在 dotnet core api 上调用控制器方法:没有中间件来处理请求

我的 dotnet 核心 api 有角度问题。我只是制作了一个登录表单和一个 UserController 来使用 jwt 处理登录请求,但是每当我点击“登录”按钮并从我的 angular 应用程序调用 UserController 的登录方法时:

this.http.post<any>(environment.baseUrl + `api/user/login`, user)
Run Code Online (Sandbox Code Playgroud)

我总是收到以下消息:

“SPA 默认页面中间件无法返回默认页面 '/index.html',因为它没有找到,并且没有其他中间件处理该请求。”

我正在寻找的不仅仅是解决方案,因为我一整天都在寻找解决它的方法,但我不知道如何解决它。我查看了 iis 日志、事件查看器日志。我尝试调试并进行了大量的互联网研究,但我找不到实际处理此类错误的正确方法

由于错误是由 dotnet 核心框架引发的,我真的不知道如何确定是我的控制器坏了还是我在配置服务时犯了错误。

你通常如何解决这个问题?提前感谢您的时间和帮助;)

启动.cs:

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        var ConnectionString = Configuration.GetConnectionString("Default"); 
        services.AddDbContext<TheCompanyContext>(options => options.UseSqlServer(ConnectionString));

        services.AddControllers();
        services.AddSpaStaticFiles(configuration =>
        {
            configuration.RootPath = $"ClientApp/dist";
        });

        services.ConfigureCORS();

        var key = Encoding.ASCII.GetBytes(Configuration["AppSettings:AuthenticationSecret"]);
        services.AddAuthentication(x =>
        {
            x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
            x.DefaultChallengeScheme = …
Run Code Online (Sandbox Code Playgroud)

c# .net-core asp.net-core-webapi angular

5
推荐指数
1
解决办法
227
查看次数

标签 统计

.net-core ×1

angular ×1

asp.net-core-webapi ×1

c# ×1