如何避免因禁用而导致的问题“访问其他域名的数据”安全政策。 [英] How to avoid ie issue due to disabled "access data across other domain" security policy.

查看:70
本文介绍了如何避免因禁用而导致的问题“访问其他域名的数据”安全政策。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

访问网络服务电话的Javascript方法,

Javascript method to access web service call,

function GetAllCitites() {
            $.support.cors = true;
            $.ajax({
                type: 'POST',
                dataType: 'jsonp',
                crossDomain: true,
                jsonpCallback: 'GetAllCitites',
                jsonp: 'callback',
                contentType: "application/json; charset=utf-8",
                url: serviceUrl + "/GetAllCitites",
                data: '{}',
                dataType: 'json',
                success: function (allData) {
                    self.Cities(allData.d);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert(textStatus);
                    //console.log("Webservice Method : GetAllCitites" + XMLHttpRequest.responseText);
                }
            });
        }





此serviceUrl是其他域名网址。



WebService.cs中的Web服务方法:



This serviceUrl is other domain url.

Webservice method in WebService.cs:

[WebMethod(Description = "Get Cities Details")]
    public List<citypartial> GetAllCitites()
    {
        List<citypartial> listCity = new List<citypartial>();

        OpenNewSession();
        List<city> list = _program.BusinessLogic.EntityStructure.Cities.FindAll(delegate(City _city)
                { return _city.Id != 35; });

        foreach (City city in list)
        {
            listCity.Add(new CityPartial
                             {
                                 CityId = city.Id,
                                 CityName = city.Name
                             }
                );
        }

        return listCity;
    } // GetAllCitites



基于成功,我使用knowout.js填充城市drowdown列表



它在所有浏览器中工作但在IE中它无法访问其他域的数据到期

即安全策略。



所以如何通过跨域启用Access数据来抑制此消息。


Based on success, i populate the city drowdown list using knowout.js

It working in all browser but in IE it not able to access the data of other domain due
to ie security policy.

So how to supress this message with enabled Access data across domain.

推荐答案

.support.cors = true ;
.support.cors = true;


.ajax({
type :' POST'
dataType:' jsonp'
crossDomain: true
jsonpCallback:< span class =code-string>' GetAllCitites'
jsonp:' callback'
contentType: application / json; charset = utf-8
url:serviceUrl + / GetAllCitites
数据:' {}'
dataType:' json'
成功:功能 (allData){
self.Cities(allData.d);
},
错误: function (XMLHttpRequest,textStatus,errorThrown ){
alert(textStatus);
// console.log(Webservice方法:GetAllCitites + XMLHttpRequest.responseText);
}
});
}
.ajax({ type: 'POST', dataType: 'jsonp', crossDomain: true, jsonpCallback: 'GetAllCitites', jsonp: 'callback', contentType: "application/json; charset=utf-8", url: serviceUrl + "/GetAllCitites", data: '{}', dataType: 'json', success: function (allData) { self.Cities(allData.d); }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert(textStatus); //console.log("Webservice Method : GetAllCitites" + XMLHttpRequest.responseText); } }); }





此serviceUrl是其他域名网址。



Webser WebService.cs中的副方法:



This serviceUrl is other domain url.

Webservice method in WebService.cs:

[WebMethod(Description = "Get Cities Details")]
    public List<citypartial> GetAllCitites()
    {
        List<citypartial> listCity = new List<citypartial>();

        OpenNewSession();
        List<city> list = _program.BusinessLogic.EntityStructure.Cities.FindAll(delegate(City _city)
                { return _city.Id != 35; });

        foreach (City city in list)
        {
            listCity.Add(new CityPartial
                             {
                                 CityId = city.Id,
                                 CityName = city.Name
                             }
                );
        }

        return listCity;
    } // GetAllCitites



基于成功,我使用knowout.js填充城市drowdown列表



它在所有浏览器中工作但在IE中它无法访问其他域的数据到期

即安全策略。



所以如何通过跨域启用Access数据来抑制此消息。


Based on success, i populate the city drowdown list using knowout.js

It working in all browser but in IE it not able to access the data of other domain due
to ie security policy.

So how to supress this message with enabled Access data across domain.


为避免此错误,您应该遵循 - 跨域ajax和IE? [ ^ ] 。不确定它是否会成功。还是试一试。



还有一个选项可以在浏览器级别设置它以接受IE中的跨域调用。

为此请参考第一种方法 - 处理跨域Ajax呼叫的两种方法 [ ^ ]。但是我不知道你是否需要这个解决方案。



如果你使用IE 8以下的浏览器版本,那么我想除了改变之外别无他法浏览器设置。



所以,试一试。祝你好运。
To avoid this error, you should follow - cross domain ajax and IE?[^]. Not sure it will work out or not. Still give it a try.

There is also an option to set this at browser level to accept the cross domain calls in IE.
For that refer the first method - Two Methods for Handling Cross-Domain Ajax Calls[^]. But I don''t know you need this solution or not.

If you are using browser version below IE 8, then I guess there is no way other than changing the browser settings.

So, try it out. Good Luck.


这篇关于如何避免因禁用而导致的问题“访问其他域名的数据”安全政策。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆