我想創建一個在MVC 5中與跨源請求(CORS)一起工作的Web應用程序。我嘗試了一切都沒有任何結果。如何在ASP.NET MVC中啓用交叉源請求
與屬性
public class AllowCrossSiteJsonAttribute: ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
filterContext.RequestContext.HttpContext.Response.AddHeader("Access-Control-Allow-Origin", "*");
base.OnActionExecuting(filterContext);
}
}
隨着EnableCors屬性
[EnableCors("*")]
沒有什麼工作,我開始認爲這是不可能
你看了樣品:https://www.asp.net/web-api/overview/security/enabling-cross- origin-requests-in-web-api –