.net webapi跨域 web.config配置

Posted eedc

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了.net webapi跨域 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>
<system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="1048576000"></requestLimits>
      </requestFiltering>
    </security>

    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Headers" value="x-requested-with" />
        <add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS,DELETE,PUT" />
        <remove name="X-Powered-By" />
      </customHeaders>
    </httpProtocol>

    <modules runAllManagedModulesForAllRequests="true">
      <remove name="WebDAVModule" />
    </modules>


    <staticContent>
      <remove fileExtension=".woff" />
      <remove fileExtension=".woff2" />
      <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
      <mimeMap fileExtension=".woff2" mimeType="application/font-woff" />
    </staticContent>
    <handlers>
      <remove name="WebDAV" />
      <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>

 

以上是关于.net webapi跨域 web.config配置的主要内容,如果未能解决你的问题,请参考以下文章

WebAPI 跨域

WebApi跨域问题

webapi 2.0 跨域行为

通过 Web.config 启用 CORS 不适用于 .net WebApi

webapi跨域使用session

PCB WebAPI跨域访问 实现方式