Web Api问题汇总

在公网上布署Web Api的时候,不能调用,返回404

在web.config中

Adding the following to the web.config file worked for me:

<system.webServer>
  <modules>
    <remove name="UrlRoutingModule-4.0" />
    <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
  </modules>
</system.webServer>

 Asp.net Mvc、webApi配置允许跨域

Web.config 下<system.webServer> 节点下配置

<httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="http://localhost:60699" />
        <add name="Access-Control-Allow-Headers" value="*" />
        <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE" />
      </customHeaders>
    </httpProtocol>

设置允许跨域传递Cookie

<system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="http://localhost:8080" />
        <add name="Access-Control-Allow-Headers" value="content-type" />
        <add name="Access-Control-Allow-Methods" value="*" />
        <add name="Access-Control-Allow-Credentials" value="true"/>
      </customHeaders>
    </httpProtocol>

 </system.webServer>

前端 请求的时候需设定:withCredentials = true; 设置了widthCredentials为true的请求中会包含远程域的所有cookie

 

posted @ 2017-08-16 11:04  ~沐风  阅读(250)  评论(0编辑  收藏  举报