Asp.Net WebService如何解决跨域问题
时间: 2024-04-30 09:17:32 浏览: 54
跨域问题可以通过在Web.config文件中配置webHttpBinding和corsBehavior来解决。具体步骤为:在Web.config文件中添加以下内容:
```xml
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webBinding" crossDomainScriptAccessEnabled="true"/>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp corsEnabled="true"/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="Service1">
<endpoint address="" binding="webHttpBinding" contract="IService1" behaviorConfiguration="webBehavior" bindingConfiguration="webBinding"/>
</service>
</services>
</system.serviceModel>
```
这样就可以实现跨域访问。
阅读全文