AJAX请求MVC控制器跨域头问题
public class AllowCrossSiteJsonAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { filterContext.RequestContext.HttpContext.Response.AddHeader("Access-Control-Allow-Origin", "*"); base.OnActionExecuting(filterContext); } }
建立一个过滤器
使用
[HttpPost] [AllowCrossSiteJson] public object Login() {}