【发布时间】:2015-01-18 02:50:05
【问题描述】:
我正在尝试使用在 MVC 4 .net WEB API 中开发的休息服务。我对 $http.get() 和 $http.get(param) 没有任何问题。当我尝试 $http.put() 时出现错误。好吧,我撒谎了。当我开始这个简单的项目时,我在使用 get 方法时遇到了同样的问题,我以这种方式管理它们:
using System;
using System.Web.Http.Filters;
public class AllowCrossSiteJsonAttribute : ActionFilterAttribute
{
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
{
if (actionExecutedContext.Response != null)
actionExecutedContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
base.OnActionExecuted(actionExecutedContext);
}
}
现在好像不行。这是 angularjs 控制台显示的错误:
http://i.stack.imgur.com/LEgwh.jpg
(我还不能放图片,所以我放了一个链接)
我应该怎么做才能使用 put 方法?
【问题讨论】:
-
你启用了 CORS 吗?
-
当我编写我在帖子中显示的这段代码时,我之所以写它是因为我在网页中读到这种方式启用了 cors。不是这样吗?我是这类应用程序的新手
标签: javascript c# asp.net angularjs