2

I would like to configure 2 hosts that allowed to access data from a webapi and 1 of those hosts can also create new objects using the POST method.

Currently my WebApiConfig.cs file looks like this:

  public static void Register(HttpConfiguration config)
    {
       //lines removed for clarity

        var cors = new EnableCorsAttribute("http://localhost:36312, http://localhost:24668", "*", "GET, POST");

        config.EnableCors(cors);

       // lines removed for clarity
    }

This will allow both hosts to use the GET and POST methods to access or create content, how can the config be setup so that the POST method is only available for the :24668 host?

neo112
  • 1,703
  • 2
  • 17
  • 39

2 Answers2

0

Look at the customization options as mentioned in this article on CORS in Web API:

http://msdn.microsoft.com/en-us/magazine/dn532203.aspx

Brock Allen
  • 7,385
  • 19
  • 24
0

You can add multiple origins by separating them with commas:

[EnableCors(origins: "http://localhost:59452,http://localhost:25495,http://localhost:8080", headers: "*", methods: "*")]

or

var cors = new EnableCorsAttribute("http://localhost:59452,http://localhost:25495,http://localhost:8080", "*", "*");

from: here

A-S
  • 2,547
  • 2
  • 27
  • 37