其他分享
首页 > 其他分享> > ajax跨域请求webservice webconfig配置

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" />

标签:选定,webservice,webconfig,配置,ajax,跨域
来源: https://www.cnblogs.com/yu-shang/p/12082638.html