随笔 - 290  文章 - 10  评论 - 85  2
    public class CORSAttribute : ActionFilterAttribute
    {
        public string Domains { get; set; }
        public CORSAttribute( string domains)
        {
            Domains = domains;
        }

        public override void OnResultExecuted(ResultExecutedContext filterContext)
        {
            filterContext.HttpContext.Response.AppendHeader("Access-Control-Allow-Origin", Domains);
            filterContext.HttpContext.Response.AppendHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
            base.OnResultExecuted(filterContext);
        }
    }

  

        [CORS("http://localhost:2339")] 
        public ActionResult Country(string keyword = "", string Lang = "zh")
        {           
            var json =xml2json(req.GetResponse(), "CountryDetails", "Name");          
            return Content(json, "text/json", Encoding.UTF8);
        }

  

posted on 2015-02-03 00:41  Gu  阅读(...)  评论(...编辑  收藏