I am getting the following error: Can't read from server. It may not have the appropriate access-control-origin settings. when the code is deployed to the server. I did a lot of research adding the Added following code in web.config
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET, POST, OPTIONS, PUT, DELETE" />
</customHeaders>
</httpProtocol>
or in the startup project
public static void Configuration(IAppBuilder app)
{
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
}
or int the webapi.config -> Register
config.EnableCors(new EnableCorsAttribute("*", "*", "*"));
Can some help? did anyone had the same issue
Its an old question but I had same issue and didn't find the permanent fix but accidentally found the workaround. So sharing it here.
Swagger URL was http://localhost/blah/swagger/ui/index#/
But the URL for swagger doc was https://localhost/blah/swagger/docs/v1
Changing doc's URL from https to http worked.
If someone have any idea why in case of the above question didnt work even though both URLs have same protocol: https, please be kind to explain.
I just face the problem and this is my solution :
.EnableSwagger(c =>
{
// By default, the service root url is inferred from the request used to access the docs.
// However, there may be situations (e.g. proxy and load-balanced environments) where this does not
// resolve correctly. You can workaround this by providing your own code to determine the root URL.
//
c.RootUrl(req =>
{
var url = req.RequestUri.Scheme ;
#if !DEBUG
url += "s";
#endif
url += "://" + req.RequestUri.Authority + System.Web.VirtualPathUtility.ToAbsolute("~");
return url;
});
});
Il permit to not use the https scheme in debug mode and use it when you release your app on a server. This solve the probleme for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With