码迷,mamicode.com
首页 > Windows程序 > 详细

asp.net webapi支持跨域

时间:2016-08-29 17:24:05      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:

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

asp.net webapi支持跨域

标签:

原文地址:http://www.cnblogs.com/94cool/p/5818424.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!