处理response设置cors返回头部信息

服务端代码:

string action = Request.QueryString["action"];
        Response.ContentType = "text/json";
        var origin = Request.Headers["Origin"];

        if (!string.IsNullOrEmpty(origin) && origin.Contains("自己的域名"))
        {
            Response.AppendHeader("Access-Control-Allow-Origin", origin);
            Response.AppendHeader("Access-Control-Allow-Methods", "GET,POST,OPTIONS");
            Response.AppendHeader("Access-Control-Allow-Headers", "*");
            Response.AppendHeader("Access-Control-Allow-Credentials", "true");
        }

前端代码:

$.ajax({
                                url: '//callfee.aspx',
                                type: 'post',
                                xhrFields: {
                                    withCredentials: true
                                },
                                success: function (res) {
                                    if(res.Status==0){
                                    }else{
                                    }
                                }
                            })

 

posted @ 2020-08-19 13:34  木子zzgxl  阅读(791)  评论(0编辑  收藏  举报