WebAPI CORS supports cross-domain post

Source: Internet
Author: User

The internet generally can be found through the Microsoft.AspNet.WebApi.Cors to achieve cors, which is through the DLL way, and then there is a way through the Config

1, DLL way to achieve cors

The advantage of this way is to control the fine, you can assign different cors settings to the action under the same site, specifically how to implement here is not much to say, do not know can see http://www.cnblogs.com/artech/p/ Cors-4-asp-net-web-api-05.html
And then here's a note of what's actually going to happen.

A) System.Web.Http failed to load

This can be downloaded directly to the DLL and then added to the project reference

b) Attempt to access security-critical types

This is because the System.Web.Http version is inconsistent, I do the test Microsoft.AspNet.WebApi.Cors version is 5.2.3, and the default is to add a System.Web.Http of 4.0, re-download the matching version through NuGet, and then adjust the reference to 5.2.3 version of the reference can fix the problem

<package id= "Microsoft.AspNet.WebApi.WebHost" version= "5.2.3" targetframework= "Net45"/>


c) error caused by default appsetting configuration

Http://diaosbook.com/Post/2013/12/27/tips-for-aspnet-webapi-cors ( Note that the Vs2013 for personal testing did not encounter this problem)


2. config method to achieve cors

The benefit of adding configuration under the System.webserver configuration section of the Web. config is simple, as long as this configuration is added here, all APIs can support cross-domain requests by the same rule

    


WebAPI CORS supports cross-domain post

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.