ASP.NET Wen API - CORS

因為有安全的問題, 所以都不會允許不同 domain 的 request data, 如果想要別人也可以用你的資料, 就必須要用 CORS
  • 去 NuGet Package Manager install Microsoft.AspNet.WebApi.Cors
  • 在 WebApiConfig.cs register CORS
  • 在想要使用 Cors 的 API Controller 的 class EnableCors
這裡可以看到有 3 個參數, 第一個是 domain, 第二個是 headers, 第三個是 methods (GET, Post…)
  • 如果不想要某一個 method 被使用, 可以 DisableCors

留言

這個網誌中的熱門文章

ASP.NET Web API - DTOs

Scaffold Identity into the Current Project

Passing data from controller to the view