How to invoke the ASP. Cross-domain call to the NET Web API (how do I implement an ASP call across domains using HTTP get in JavaScript?) )

Source: Internet
Author: User

Client-side JS does not require any special settings, using the usual Ajax calls:

$.ajax ({    URL: ' Cross-domain URL ',    type: ' Get ',    dataType: ' json ',    success:function (data) {        $ (' #banner_ Right '). HTML (data);}    });

The server needs to add the following code in Webapiconfig.register ()

public static class webapiconfig{public    static void Register (httpconfiguration config)    {        var cors = new Enab Lecorsattribute ("http://www.cnblogs.com,http://news.cnblogs.com", "*", "*");        Config. Enablecors (cors);                }}

Note 1: "http://www.cnblogs.com,http://news.cnblogs.com" means that the 2 domain names are allowed to invoke this web API across domains.

NOTE 2: NuGet installation Required Microsoft.AspNet.Cors

How to invoke the ASP. Cross-domain call to the NET Web API (how do I implement an ASP call across domains using HTTP get in JavaScript?) )

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.