Web Api:  vs2013 only
http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api#enable-cors
1. install cors package through package manager console
Install-Package Microsoft.AspNet.WebApi.Cors -pre -project WebService

2. Add to api cofig
 public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            // New code
            config.EnableCors();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }
    }
3. enable on apiController
namespace WebService.Controllers
{
    [EnableCors(origins: "http://myclient.azurewebsites.net", headers: "*", methods: "*")]
    public class TestController : ApiController
    {
        // Controller methods not shown...
    }
}
4. some time you need $.support.cors = ture; before you make jsonp call



for WCF, congig it in webHttpbinding section of web.config:

 <webHttpBinding>
        <binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true" />
      </webHttpBinding>

If you use SignalR.
http://www.asp.net/signalr/overview/hubs-api/hubs-api-guide-javascript-client#crossdomain
var hubConfiguration = new HubConfiguration();
hubConfiguration.EnableCrossDomain = true;
RouteTable.Routes.MapHubs(hubConfiguration);

Client code that specifies a cross-domain connection (with the generated proxy)
$.connection.hub.url = 'http://fabrikam.com/'
$.connection.hub.start().done(init);

Client code that specifies a cross-domain connection (without the generated proxy)

var connection = $.hubConnection('http://fabrikam.com/');



 
Comments are closed.