Skip to content

CORS: Incorrect Status Code for OPTIONS endpoint #36592

Merged
tdykstra merged 4 commits into
mainfrom
copilot/update-aspnetcore-web-hosting
May 12, 2026
Merged

CORS: Incorrect Status Code for OPTIONS endpoint #36592
tdykstra merged 4 commits into
mainfrom
copilot/update-aspnetcore-web-hosting

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 8, 2026

Fixes #36526


Internal previews

📄 File 🔗 Preview link
aspnetcore/security/cors.md Enable Cross-Origin Requests (CORS) in ASP.NET Core

Copilot AI changed the title [WIP] Update ASP.NET Core web hosting documentation Initial analysis plan for issue #36526 Jan 8, 2026
Copilot AI requested a review from tdykstra January 8, 2026 18:57
@tdykstra tdykstra changed the title Initial analysis plan for issue #36526 CORS: Incorrect Status Code for OPTIONS endpoint Apr 9, 2026
@tdykstra tdykstra marked this pull request as ready for review May 12, 2026 03:37
@tdykstra tdykstra requested review from Copilot and wadepickett May 12, 2026 03:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the CORS documentation to correct the expected HTTP status code returned when an ASP.NET Core CORS preflight (OPTIONS) request is denied, aligning the article with observed middleware behavior and the linked issue report.

Changes:

  • Updated two statements in the CORS article to indicate denied preflight requests return 204 No Content (instead of 200 OK).
  • Kept the existing guidance that denied preflight responses omit CORS headers, causing the browser to block the cross-origin request.

Comment thread aspnetcore/security/cors.md Outdated
* [Access-Control-Request-Headers](https://developer.mozilla.org/docs/Web/HTTP/Headers/Access-Control-Allow-Headers): A list of request headers that the app sets on the actual request. As stated earlier, this doesn't include headers that the browser sets, such as `User-Agent`.

If the preflight request is denied, the app returns a `200 OK` response but doesn't set the CORS headers. Therefore, the browser doesn't attempt the cross-origin request. For an example of a denied preflight request, see the [Test CORS](#testc6) section of this document.
If the preflight request is denied, the app returns a `204 No Content` response but doesn't set the CORS headers. Therefore, the browser doesn't attempt the cross-origin request. For an example of a denied preflight request, see the [Test CORS](#testc6) section of this document.
* [Access-Control-Request-Headers](https://developer.mozilla.org/docs/Web/HTTP/Headers/Access-Control-Allow-Headers): A list of request headers that the app sets on the actual request. As stated earlier, this doesn't include headers that the browser sets, such as `User-Agent`.

If the preflight request is denied, the app returns a `200 OK` response but doesn't set the CORS headers. Therefore, the browser doesn't attempt the cross-origin request. For an example of a denied preflight request, see the [Test CORS](#testc6) section of this document.
If the preflight request is denied, the app returns a `204 No Content` response but doesn't set the CORS headers. Therefore, the browser doesn't attempt the cross-origin request. For an example of a denied preflight request, see the [Test CORS](#testc6) section of this document.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tdykstra , Line 250 uses an astrisk around the reponse and this ilne 367 uses backticks around the "returns a 204 No Content response". Should both cases use backticks?

Copy link
Copy Markdown
Contributor

@wadepickett wadepickett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tdykstra, looks great! Only a minor item to look at regarding backticks around 204 No Content. Approved.

tdykstra and others added 2 commits May 12, 2026 10:32
Update the date for the CORS documentation.
Replace asterisks with backticks for ` 204 new content`

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@tdykstra tdykstra merged commit 581c88a into main May 12, 2026
4 checks passed
@tdykstra tdykstra deleted the copilot/update-aspnetcore-web-hosting branch May 12, 2026 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CORS: Incorrect Status Code For OPTIONS endpoint

4 participants