zoukankan      html  css  js  c++  java
  • 引用 AspNetCoreRateLimit => StatusCode cannot be set because the response has already started.

    app.UseIpRateLimiting(); #需要放在前面,否则抓去不准,还有可能会出现下列错误

    本次出现这个错误,是因为  .Net Core 跨域

    里面的这行:httpContext.Response.StatusCode = 204; 由于StatusCode 先给它设了 204,所以导致 IpRateLimit 报了下图的错误。
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        app.UseIpRateLimiting(); #需要放在前面
    
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
            app.UseStatusCodePagesWithReExecute("/Home/Error");
        }
        
        //..............
    }
    
    app.UseIpRateLimiting(); #需要放在前面,否则抓去不准,还有可能会出现下列错误
    fail: Microsoft.AspNetCore.Server.Kestrel[13]
          Connection id "0HM084E4TPLBN", Request id "0HM084E4TPLBN:00000001": An unhandled exception was thrown by the application.
    System.InvalidOperationException: StatusCode cannot be set because the response has already started.
       at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ThrowResponseAlreadyStartedException(String value)
       at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.set_StatusCode(Int32 value)
       at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.Microsoft.AspNetCore.Http.Features.IHttpResponseFeature.set_StatusCode(Int32 value)
       at Microsoft.AspNetCore.Http.DefaultHttpResponse.set_StatusCode(Int32 value)
       at Microsoft.AspNetCore.Routing.Matching.HttpMethodMatcherPolicy.<>c__DisplayClass15_0.<CreateRejectionEndpoint>b__0(HttpContext context)
       at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)
    --- End of stack trace from previous location where exception was thrown ---
       at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
       at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
       at AspNetCoreRateLimit.RateLimitMiddleware`1.Invoke(HttpContext context)
       at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
       at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
       at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.HandleException(HttpContext context, ExceptionDispatchInfo edi)
       at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
       at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)

  • 相关阅读:
    安装Bind到CentOS(YUM)
    安装Ansible到CentOS(YUM)
    安装AB到CentOS(YUM)
    安装APACHE到CentOS(YUM)
    07 Spring Cloud Eureka是什么?
    06 Spring Boot Starter的介绍及使用
    05 Spring Boot项目搭建步骤(超详细)
    04 Spring Cloud开发环境的准备和Lombok安装步骤
    03 Spring Cloud和Dubbo的区别及各自的优缺点
    02 Spring Cloud 模块介绍
  • 原文地址:https://www.cnblogs.com/vipsoft/p/13043147.html
Copyright © 2011-2022 走看看