Allows ASP. NET MVC to be accessed across domains without using JSONP

Source: Internet
Author: User

A cross-domain problem occurs only when JavaScript initiates an Ajax call, or when Silverlight initiates a service invocation, because the browser is given a lower permission for both requests, usually allowing only the resources in the domain to be called. Unless the target server explicitly tells it to allow cross-domain calls.

Therefore, the cross-domain problem is caused by the behavior of the browser, but the solution is on the server side. Because it is not possible to require all clients to reduce security.

Solution Solutions

For the ASP. NET MVC project type, I did some research to make sure that the following scenario is feasible.

For ASP. NET MVC, just add the following in Web. config

<system.webServer>

<customHeaders>

<add name= "Access-control-allow-origin" value= "*"/> <!--<add name= "Access-control-allow-origin" value= " http://localhost:24066 "/>value can set access only to a domain name, only one value--

<add name= "Access-control-allow-headers" value= "Content-type"/>

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

</customHeaders>

</system.webServer>

Allows ASP. NET MVC to be accessed across domains without using JSONP

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.