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
c # .net cors asp.net-web-api


source to share


No one has answered this question yet

See similar questions:

58
How do I do CORS authentication in WebAPI 2?

or similar:

780
How to enable build failure logging (Fusion) in .NET.
603
Why is adding CORS headers to the OPTIONS route preventing browsers from accessing my API?
6
Swagbuckle swagger not working
2
WebApi 2 with OWIN - Challenge authorization not redirecting to login
2
Self-service signaling with TLS 1.2
2
Calling Application_Start on Owin Self-Hosting Application
1
OWIN Katana, Webapi, MVC all in separate projects
1
Not allowed to use Owin self-hosted WCU method at DELETE level
0
WebApi multicast routing not working with AngularJs attribute based routes
0
Can't resolve Uwin host's HTTP configuration



All Articles
Loading...
X
Show
Funny
Dev
Pics