.net Nancy在500错误时返回CORS错误

.net Nancy在500错误时返回CORS错误,.net,nancy,http-status-code-500,.net,Nancy,Http Status Code 500,我有一个使用Nancy运行的.NET应用程序。我可以通过react应用程序成功地从API端点获取数据,但是如果出现服务器端错误,则会出现CORS错误 我在Postman中没有收到CORS错误,尽管我在输入CORS代码之前从来没有收到过 Cors扩展 public static void UseCors(this IPipelines pipelines) { pipelines.AfterRequest.AddItemToEndOfPipeline(ctx =&g

我有一个使用Nancy运行的.NET应用程序。我可以通过react应用程序成功地从API端点获取数据,但是如果出现服务器端错误,则会出现CORS错误

我在Postman中没有收到CORS错误,尽管我在输入CORS代码之前从来没有收到过

Cors扩展

    public static void UseCors(this IPipelines pipelines)
    {
        pipelines.AfterRequest.AddItemToEndOfPipeline(ctx => ctx.Response
            .WithHeader("Access-Control-Allow-Origin", "*")
            .WithHeader("Access-Control-Allow-Methods", "GET,POST,DELETE,PUT,OPTIONS")
            .WithHeader("Access-Control-Allow-Headers", "Accept, Origin, Content-Type"));
    }
引导程序

    protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context)
    {
        pipelines.UseCors();
        pipelines.UseErrorResponses();

        base.RequestStartup(container, pipelines, context);
    }
我在Google Chrome控制台中得到的错误是:

无法加载获取API。请求的资源上不存在“Access Control Allow Origin”标头。因此,不允许访问源“”。响应的HTTP状态代码为500。如果不透明响应满足您的需要,请将请求的模式设置为“no cors”,以获取禁用cors的资源

我曾尝试将CORS头添加到
OnError
管道中,但似乎没有任何改变