1

I've configured Swagger for my Web API 2.2 app and it loads locally but I get a CORS error when I try to access it on a remote server. Also, just to get to the swagger page I have to be very explicit with the url. For example:

https://example.com/swagger/ui/index

As opposed to:

example.com/swagger/

I think I encountered a somewhat similar issue on a previous project where I had to provide the full explicit url as displayed in my first example, but on this previous project, using the long form url displayed the working swagger page as expected. Is this due to https configuration? Is there a special swagger setting that can be configured to allow the short url in an https environment? On remote servers the following error message displays which appears to clearly indicate a CORS error:

"Can't read from server. It may not have the appropriate access-control-origin settings."

I've tried everything in the following thread but I'm still having the issue:

CORS support for PUT and DELETE with ASP.NET Web API

If I submit an API search request to the remote server then a response header of "Access-Control-Allow-Origin > *" is returned so it appears that CORS is enabled for the remote server. Not sure why swagger is encountering what appears to be a CORS error?

user9393635
  • 1,369
  • 4
  • 13
  • 32

1 Answers1

0

You need to specify the complete root url at the SwaggerConfig file. You might be facing this as when you run on local the API is accessed via HTTP but on Server it would be HTTPs, causing the CORS issue, as your SwaggerCongif would still be by default pointing to the HTTP path.

Utkarsh Bais
  • 197
  • 8