一、WebConfig配置法(system.webServer 重点是 httpProtocol handlers)

http://www.jinxuliang.com/blog/article/read/3348d442-9432-49d8-abe9-2c64ce6436cd

http://www.matlus.com/rest-apis-put-and-delete-cause-http-error-404/  *

2个内容配合使用 ,第二个连接的方法,会自动改Web.config

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

 二、终级Global.asax代码处理方法

 //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();
} }

最新文章

  1. 设计模式(十二)享元模式(Flyweight Pattern)
  2. jmeter 内存溢出解决方法
  3. 消息队列写入内容后,读出来的自动包裹了&lt;string&gt;标签,自定义格式化器解决该issue
  4. Oracle 创建/删除 表空间、用户、授权
  5. css3中clip属性
  6. 12天学好C语言——记录我的C语言学习之路(Day 6)
  7. 利用反射把查询到的Table、Reader转换成List、Model
  8. DataSnap
  9. VR问题无关方向,VR全景为您领航,全景智慧城市已势不可当
  10. VC++平台上的内存对齐操作
  11. maven入门(8)maven的依赖管理
  12. 深海中的STL—nth_element
  13. 《R语言入门与实践》第三章:R 对象
  14. stark组件开发之列表页面自定义函数扩展
  15. Nginx配置服务器静态文件支持跨域访问
  16. Visual Studio项目的生成事件代码
  17. ubuntu系统创建新用户并赋予sudo权限
  18. 忘记MySQL root密码重置MySQL root密码
  19. js一种继承机制:用对象冒充继承构造函数的属性,用原型prototype继承对象的方法。
  20. 品味性能之道&lt;三&gt;:方法论

热门文章

  1. [P2058][NOIP2015]海港 (模拟)
  2. python网络编程(十三)
  3. opencv+python 自动绿帽机
  4. cookies和session
  5. Nand_ECC_校验和纠错_详解
  6. poj3280 Cheapest Palindrome(回文串区间dp)
  7. centOS --- 安装最新版的node nodejs
  8. Lua模块的加载与内存释放
  9. springboot获取properties文件的配置内容(转载)
  10. javaweb中使用百度、谷歌地图进行定位