asp.net webapi支持跨域

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
    {
            }
}

上一篇:mina框架详解


下一篇:First Position of Target