简体   繁体   中英

Web API - Protect GET from anchor tag using CORS

i have created a GET web api method that is going to be referred to from an anchor tag outside of my application (one of our vendors).

i was thinking this would not work out of the box because of CORS but I guess this only happens when making calls via javascript / ajax ???

what would be a good solution to ensure this method is only called by certain domains (including our site)?

refer this link it should give you the information you are looking

Checkout the section Set the Allowed Origins

  [EnableCors(origins: "http://example.com, http://example1.com", headers: "*", methods: "*")]
   public class Controller1 : ApiController
   {
    ...
   }

Put this attribute above your controller class Replace http://example.com and http://example1.com with domains you want to allow

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM