【问题标题】:Authentication issue in jsonp ria servicesjsonp ria 服务中的身份验证问题
【发布时间】:2012-06-16 08:19:07
【问题描述】:

我正在使用带有 jsonp 端点的 ria 服务。当我在服务文件中调用我的方法时,它在 ie 和 firefox 中运行良好,但有时在 chrome 中运行,有时我得到“经过身份验证的服务不支持跨域 javascript 回调”。错误。即使我不使用经过身份验证的服务。

这是一段关于我所拥有的代码。

Jsonp 服务

    [EnableClientAccess(RequiresSecureEndpoint = false)]
    public class PPolJsonService : LinqToEntitiesDomainService<PPolAdvEntities>
    {

       public IQueryable<QuestionEntity> GetCompleteSurvey()
       {
        ............
       }
    }

javascript 代码

 function (data) {
                        var Params = {};
                        Params.type = 'GET';
                        Params.url = 'http://127.0.0.1:81/PPolSilverlight-Web-Services-PPolJsonService.svc/JSONP/GetCompleteSurvey;
                        Params.dataType = 'jsonp';

                        Params.data = { data:'somedata'};
                        Params.success = function (data) { };
                        Params.jsonpCallback = "ppolv2"
                        $.ajax(Params);
                    });

在 web.config 文件中我的设置​​是&lt;authentication mode="Forms"&gt;

如果我设置了&lt;authentication mode="None"&gt;,我就能够解决 chrome 的所有问题。但是应用程序的其余部分需要身份验证。所以这就是为什么我必须将它用作“mode=Forms”。如您所见,我的服务不使用身份验证,

为什么我会收到这个错误,有什么解决办法吗?

注意:

顺便说一下,我在 web.config 中还有其他设置,例如

  <webHttpEndpoint>
        <standardEndpoint crossDomainScriptAccessEnabled="true"
                          automaticFormatSelectionEnabled="true"/>
      </webHttpEndpoint>

或者这些在clientaccesspolicy.xml中

<?xml version="1.0" encoding="utf-8"?>
<access-policy>
  <cross-domain-access>
    <policy>
      <allow-from http-request-headers="*">
        <domain uri="http://*"/>
        <domain uri="https://*" />
      </allow-from>
      <grant-to>
        <resource path="/" include-subpaths="true"/>
      </grant-to>
    </policy>
  </cross-domain-access>
</access-policy>

但他们都没有帮助我。

提前致谢。

【问题讨论】:

    标签: asp.net authentication cross-domain jsonp ria


    【解决方案1】:

    我的测试还不够,但我想我找到了解决方案。

    如果您在应用程序中使用安全端点,并且您不需要为 jsonp 服务使用安全端点,

    你可以在

    中添加requireSSL="true"
     <authentication mode="Forms">
      <forms name=".PPolSilverlight_ASPXAUTH" timeout="2880" requireSSL="true" />
    </authentication>
    

    使用这小段代码,您的不安全 jsonp 服务将无需身份验证即可工作。

    【讨论】:

      【解决方案2】:

      您好尝试将此行添加到您的 web.config 文件中。它支持跨域 Ajax 请求。

      <?xml version="1.0" encoding="utf-8"?>
      <configuration>
       <system.webServer>
         <httpProtocol>
           <customHeaders>
             <add name="Access-Control-Allow-Origin" value="*" />
           </customHeaders>
         </httpProtocol>
       </system.webServer>
      </configuration>
      

      【讨论】:

      • 您是否在同一个 iis 站点上发布了服务和网站?如果是,则尝试在 Params.url 中使用相对路径。
      • 不幸的是,此 javascript 需要从任何网页调用。所以它们不在同一个 iis 站点上。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多