1、Install-Package Microsoft.AspNet.WebApi.Cors
2、
using System.Web.Http;
namespace WebService
{
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.EnableCors();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
}
3、
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Cors;
namespace WebService.Controllers
{
[EnableCors(origins: http://www.***.com, headers: "*", methods: "*")]
public class TestController : ApiController
{
}
}
本文转自94cool博客园博客,原文链接:http://www.cnblogs.com/94cool/p/5818424.html,如需转载请自行联系原作者