This article is a mirror article of machine translation, please click here to jump to the original article.

View: 2958|Reply: 0

[.NET Core] ASP.NET Core exception Headers are read-only, response has already started

[Copy link]
Posted on 7/11/2024 9:44:40 AM | | | |
Requirements: ASP.NET Core modifies the response header Server information in the middleware, error: System.InvalidOperationException: Headers are read-only, response has already started.

Misspelling:

The error is as follows:

fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HN519819L24M", Request id "0HN519819L24M:00000001": An unhandled exception was thrown by the application.
      System.InvalidOperationException: Headers are read-only, response has already started.
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpHeaders.ThrowHeadersReadOnlyException()
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpResponseHeaders.Microsoft.AspNetCore.Http.IHeaderDictionary.set_Server(StringValues value)


The cause of the anomaly is becauseWhen the ASP.NET Core has already started responding, the Headers are not allowed to be modified again, that is, when the response starts, the headers will become read-only.

The solution is as follows:



As shown below:





Previous:Nginx enables the HTTP/3 protocol based on QUIC
Next:Use the dotnet-ef tool to generate a rollback script
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com