欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

webapi 跨域问题

程序员文章站 2022-06-24 13:55:46
参考:http://www.cnblogs.com/chenxizhang/p/3821703.html 给自己做个笔记 在web.config中添加这段代码 ......

参考:

给自己做个笔记

 httpcontext.current.response.addheader("access-control-allow-credentials", "true");
 httpcontext.current.response.addheader("access-control-allow-headers", "origin,x-requested-with,content-type");
 httpcontext.current.response.addheader("access-control-allow-methods", "post,get,options");
 httpcontext.current.response.addheader("access-control-allow-origin", "*");

在web.config中添加这段代码

<system.webserver>
<httpprotocol>
<customheaders>
<add name="access-control-allow-origin" value="*" />
<add name="access-control-allow-headers" value="content-type" />
<add name="access-control-allow-methods" value="get, post, put, delete, options" />
</customheaders>
</httpprotocol>
<handlers>
<remove name="extensionlessurlhandler-integrated-4.0" />
<remove name="optionsverbhandler" />
<remove name="traceverbhandler" />
<add name="extensionlessurlhandler-integrated-4.0" path="*." verb="*" type="system.web.handlers.transferrequesthandler" precondition="integratedmode,runtimeversionv4.0" />
</handlers>
</system.webserver>