ajax跨域请求webservice webconfig配置
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Methods" value="OPTIONS,POST,GET"/>
<add name="Access-Control-Allow-Headers" value="x-requested-with,content-type"/>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
<modules>
<add name="MyHttpModule" type="WebServiceDemo.MyHttpModule"/>
</modules>
</system.webServer>
如果想选定的网站可能跨域访问,修改配置如下
<add name="Access-Control-Allow-Origin" value="http://domain1.com, http://domain2.com" />
Thanks & Best Regards!
Javi Zhu 朱佳辉
Mobile: 15900467108
Email: Javi.zhu@outlook.com