都说我不存在

导航

 

参照了网上的很多资料,vs2012

项目是wcf服务.

.demo地址https://files.cnblogs.com/files/dswyzx/WcfServiceDemoa.rar

 

2019年了.我来更新一下:https://github.com/dswyzx/WcfServiceDemoa

其实跨域操作的实现是在global里注册了管道事件.

        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            //josn post请求第一次发出的OPTIONS,不返回
            // HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
            if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
            {
                HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "PUT, DELETE");//POST, 
                HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
                HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
                HttpContext.Current.Response.End();
            }
        }

 

鉴于此文章写于2016年.就此作罢.跨域的理论方面,廖雪峰网站描写的还不错,跨域的实现,nuget找Cors关键字,然后上图的设置可以写在config里就酱

posted on 2016-11-15 17:15  都说我不存在  阅读(338)  评论(0编辑  收藏  举报