2016-09-27 59 views
-1

我有一個Angular2應用程序和ASP.NET網頁API 2 CORS全局啓用: enter image description here到預檢要求CORS響應當端點需要參數

,並與後一個控制器,以登錄模式(電子郵件和密碼字符串)enter image description here

,並從客戶端的請求: enter image description here

,如果我離開參數爲空,我沒有問題,從我的前端調用它,但如果我離開它,要求loginmodel,我得到f ollowing: enter image description here 和要求: enter image description here

誰能告訴這怎麼可能呢?至少如何解決它。

回答

0

我無法解釋這一點,但它的工作。 我刪除:

  var cors = new EnableCorsAttribute("*", "*", "*"); 
      config.EnableCors(cors); 

從我WebApiConfig,反而增加了以下到我的web.config:

<system.webServer> 
<httpProtocol> 
    <customHeaders> 
    <!-- This enables your CORS Requests to be accepted. --> 
    <add name="Access-Control-Allow-Origin" value="*" /> 
    <add name="Access-Control-Allow-Headers" value="Content-Type" /> 
    <add name="Access-Control-Allow-Credentials" value="true" /> 
    <add name="Access-Control-Allow-Methods" value="GET, POST, OPTIONS" /> 
    </customHeaders> 
</httpProtocol> 

我之所以沒有從beginnig做到這一點的是,我的Web API 2沒有system.webserver,它有一個system.web,我不知道我可以兼得。如果有人能夠對此有所瞭解,請做