<system.webServer>
<!--IIS7/7.5上必须加这个配置,否则访问报错-->
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule"/>
</modules>
<validation validateIntegratedModeConfiguration="false"/>
<!--以下配置为了让IIS7+支持Put/Delete方法(CORS)-->
<httpProtocol>
<customHeaders>
<!--<add name="Access-Control-Allow-Origin" value="http://*.com" />-->
<!--<add name="Access-Control-Allow-Origin" value="http://local*:49356" />-->
<add name="Access-Control-Allow-Methods" value="GET,POST,PUT,DELETE,PATCH,OPTIONS"/>
<add name="Access-Control-Allow-Headers" value="Accept,Content-Type,X-Requested-With"/>
<add name="Access-Control-Allow-Credentials" value="true"/>
<!-- 跨域session保持 -->
</customHeaders>
</httpProtocol>
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit"/>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit"/>
<remove name="WebDAV"/>
<remove name="OPTIONSVerbHandler"/>
<!--跨域重点配置-->
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0"/>
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0"/>
</handlers>
</system.webServer>
<remove name="OPTIONSVerbHandler"/>
//cros 跨域请求配置
protected void Application_BeginRequest(object sender, EventArgs e)
{
string origin = HttpContext.Current.Request.Headers["Origin"];
if (origin != null)
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", origin);
}
else
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
}
if (HttpContext.Current.Request.HttpMethod == "OPTIONS" && Request.RawUrl.ToLower().Contains(".asmx/"))
{
HttpContext.Current.Response.End();
}
}