小编Noa*_*ani的帖子

MVC web api:请求的资源上没有"Access-Control-Allow-Origin"标头

我尝试了本文中所写的所有内容:http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api,但没有任何作用.我正在尝试从webAPI2(MVC5)获取数据以使用angularJS在另一个域中使用.

我的控制器看起来像这样:

namespace tapuzWebAPI.Controllers
{
    [EnableCors(origins: "http://local.tapuz.co.il", headers: "*", methods: "*", SupportsCredentials = true)]
    [RoutePrefix("api/homepage")]
    public class HomePageController : ApiController
    {
        [HttpGet]
        [Route("GetMainItems")]
        //[ResponseType(typeof(Product))]
        public List<usp_MobileSelectTopSecondaryItemsByCategoryResult> GetMainItems()
        {


            HomePageDALcs dal = new HomePageDALcs();
            //Three product added to display the data

            //HomePagePromotedItems.Value.Add(new HomePagePromotedItem.Value.FirstOrDefault((p) => p.ID == id));


            List<usp_MobileSelectTopSecondaryItemsByCategoryResult> items = dal.MobileSelectTopSecondaryItemsByCategory(3, 5);
            return items;

        }      
    }
}
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc cors asp.net-web-api angularjs

114
推荐指数
6
解决办法
17万
查看次数

标签 统计

angularjs ×1

asp.net-mvc ×1

asp.net-web-api ×1

c# ×1

cors ×1