Enable CORS in OWIN Self Hosted WebApi
I'm trying to get CORS to work in WebAPI, which itself is hosted in OWIN. The code I have is
public void Configuration(IAppBuilder appBuilder)
{
var configuration = new HttpConfiguration();
appBuilder.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
appBuilder.UseWebApi(configuration);
configuration.Routes.Add("API Default", new HttpRoute("{Controller}"));
appBuilder.Run((owinContext) =>
{
owinContext.Response.ContentType = "text/plain";
return owinContext.Response.WriteAsync("Api is available at: /ReceiptPrinter");
});
}
Whenever I access it from a secure page, I get an unsafe error and the browser blocks the request.
Can this be done?
I have answers like http://rion.io/2013/06/03/using-cors-in-asp-net-webapi-without-being-a-rocket-scientist/ but they don't seem to work with self-organized applications.
+3
source to share
No one has answered this question yet
See similar questions:
or similar: