-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CORS does not function on swagger.json endpoint #2641
Comments
@rcollette , I don't believe this is, or has anything to do with Swashbuckle, but I can tell you that we had, what I believe to be, the same problem. The problem has to do with the order in which you add middleware to the ASP.NET processing pipeline. You showed adding CORS with the
The key thing to note is that the adding of Swagger comes before the adding of CORS. What we discovered is that the Swagger middleware, when it knows that the request is for itself, it won't forward the request onto any further middleware handlers. It simply returns the response to the web browser and then stops the server from doing any more processing. So we had to change our code to the following:
You now see that the CORS middleware is added to the request pipeline before the Swagger middleware is added, therefore, the CORS middleware will get a chance to process the request before Swagger processes it, and the CORS middleware will be able to properly modify the response with the necessary CORS headers, if needed. Hopefully that is your issue as well, and if so, then you'll be able to close this bug, as it is not related to Swashbuckle. |
As noted above, this is likely a middleware ordering issue. Please open a new issue if you still encounter the problem with appropriately ordered middleware so that CORS is applied before Swashbuckle is registered. |
My API application is configured to allow cross domain requests by setting:
and
When a request to any of my APIs contains the
Origin
request header with a value ofhttp://localhost:4200
the http response headeraccess-control-allow-origin
is set tohttp://localhost:4200
. CORS configuration is working.When a request is made to the swagger.json endpoint rendered by Swashbuckle, and the Origin request header is included as mentioned previously, no
access-control-allow-origin
header is included in the response.I am unable to locate any documentation that mentions separate configuration required for Swashbuckle to handle CORS requests.
The text was updated successfully, but these errors were encountered: