Ajax JSON cross-domain Request service (WEBAPI,WCF or other)

Source: Internet
Author: User

Come straight to the dry.

The program works under a single IIS, and the domain name (load balancer) opens up various cross-domains. Under the study, a solution can be generally used as long as the following conditions are met:

Conditions are:

1. HTTP method: Methods other than Get,head,post

2. Use the Post method, and use application/x-www-form-urlencoded, Multipart/form-data, or text/plain other than Content-type, for example: Send XML as POST , JSON, etc.

3. Use a custom header

Solution:

Remove the optionsverbhandler Handle Mapping under IIS,

Or add in the Webconfig type:

<system.webServer>"optionsverbhandler" / >      <!--and    
View Code

or intercept the options request directly,

  

if (Request. Method.method==httpmethod.options.method)                {                    return base. SendAsync (Request, CancellationToken). ContinueWith (                        task = {return request. Createresponse (Httpstatuscode.ok); }                            );                }

The reason for this is that AJAX requests always send an options before sending a normal request. While IIS default to the options of the direct interception, do not do processing, directly return, but did not include the Access-control-allow-origin Header, so the request failed, there is no second normal request.

Ajax JSON cross-domain Request service (WEBAPI,WCF or other)

Related Article

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.