Enable OWIN Cross-origin Request

Source: Internet
Author: User

Microsoft has a solution to "Allow WEBAPI CORS requests"


Http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api


If you use Owin at the same time, even if you use this, you cannot make Owin allow Cross-origin requests.

OWIN is a set of OAUTH2.0 solutions based on Kantana.


So to use DLL Microsoft.OWIN.Cros

I installedMicrosoft.Owin.CorsThe package is on the API Server. InchStartup.Auth.csFile, underpublic void ConfigureAuth(IAppBuilder app), I added in

app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);

InchWebApiConfig.cs, underpublic static void Register(HttpConfiguration config), I added in these lines:

// Corsvar cors = new EnableCorsAttribute("*", "*", "GET, POST, OPTIONS");config.EnableCors(cors);

Or the most direct method ()!!!!

<customHeaders>
<add name= "Access-control-allow-origin" value= "*"/>
<add name= "Access-control-allow-methods" value= "GET, POST, OPTIONS, PUT, DELETE"/>
</customHeaders>

Add this section to the <system.webServer> node of Web. config, success!


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.