【问题标题】:Under IIS6, Post Data (method arguments) in jquery ajax post to WCF service is nulled out in IE (unless fiddler is running)在 IIS6 下,jquery ajax post 到 WCF 服务中的 Post Data(方法参数)在 IE 中无效(除非 fiddler 正在运行)
【发布时间】:2011-09-07 02:20:04
【问题描述】:

关于这个问题已经有一段时间了。

在 IIS6 和 windows 身份验证下,每当我尝试使用 jquery 发布到 WCF 服务时,都会调用并执行服务方法,但所有发布数据(方法参数)都是空的。这似乎只发生在该机器上的 IE8 版本上。这在 Firefox 中不会发生,奇怪的是,当 fiddler 运行时(充当代理)也不会发生这种情况。

此代码在 IIS7 下运行良好,在 IIS6 匿名身份验证下似乎运行良好。

帖子数据只是 JSON。

$.callService('GetCurrentTemplates', pagingData, GetCurrentTemplateSucceeded, ServiceFailed);

$.callService = function (url, data, successHandler, failHandler) {
    var applicationUrl = $("#hdApplicationUrl").val();
    $.ajax({
        type: "POST", //GET or POST or PUT or DELETE verb
        url: applicationUrl + "Service.svc/" + url, // Location of the service
        data: $.jsonSerialize(data), //Data sent to server
        contentType: "application/json; charset=utf-8", // content type sent to server
        dataType: "json", //Expected data format from server
        processdata: true, //True or False
        success: function (result) {
            if (result == null) {
                var resultObj = new Object();
                resultObj.status = 401;
                resultObj.statusText = 'Unauthorized';
                $.showError(resultObj);
                return;
            }
            if (successHandler != null && successHandler != undefined)
                successHandler(result);
        }, // When success
        error: function (result) {
            $.showError(result);
        } // When Service call fails
    });

WCF 服务被设计为使用 WebServiceHostFactory 和 web.config 定义如下:

<services>
  <service name="Company.Core.TemplateService" behaviorConfiguration="templateWcfBehavior">
    <endpoint address="" binding="webHttpBinding" bindingConfiguration="templateWebHttpBinding" behaviorConfiguration="jsonEndpointBehavior" contract="Company.Core.ITemplateService" />
  </service>
</services>

<behaviors>
    <endpointBehaviors>
        <behavior name="jsonEndpointBehavior">
            <webHttp />
        </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
        <behavior name="templateWcfBehavior">
            <serviceMetadata httpGetEnabled="true" />
            <serviceDebug includeExceptionDetailInFaults="false" />         
        </behavior>
    </serviceBehaviors>
</behaviors>

<webHttpBinding>
<binding name="templateWebHttpBinding" maxReceivedMessageSize="2147483647">
  <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</webHttpBinding>

服务文件当然是在匿名访问(不是 Windows 身份验证)下。

如果我们在匿名访问下运行 -everything-,jquery 会将适当的数据传递给服务,方法会返回我们想要的,等等。如果我们在集成模式身份验证下运行但在客户端上有提琴手,也会发生同样的情况.

似乎 Fiddler 正在对数据包进行变异以修复一个明显的缺陷 - 遇到问题,因为该问题似乎只发生在机器本地(排除使用 wireshark/ethereal 来嗅探数据包并确定确切的差异)。

此时,您可以提供的任何建议/信息都会非常有帮助。

2011-09-07 更新:很有趣,如果我联系服务(并且 asp.net 启动它) - 然后我可以将服务从匿名访问更改为 Windows 集成身份验证。虽然该服务已经启动并激活,但这实际上会导致一切正常运行。如果我等待 IIS6 将元数据库更改刷新到磁盘并运行 IISreset(或回收应用程序池),它会失败。它失败的原因是“此服务的安全设置需要'匿名'身份验证,但托管此服务的 IIS 应用程序未启用它。”。看来我进退两难了。无论出于何种原因,在匿名访问下,我的论点帖子设置都会丢失。如果服务已经启动,我可以将文件更改为集成模式身份验证,一切都会正常工作。如果服务未启动(或在应用程序池回收时丢失)并且设置为集成模式身份验证,我会因上述错误而失败。大佬们!

【问题讨论】:

    标签: c# asp.net wcf fiddler


    【解决方案1】:

    原因似乎是一旦 IE 遇到 NTLM,它就会要求站点上的所有其他页面使用 NTLM。见http://support.microsoft.com/?id=251404 “您不能将数据发布到未经 NTLM 身份验证的网站”

    建议的解决方法是,如果您在任何设备上启用 NTLM,请在所有设备上启用 NTLM。

    替代解决方法是更改​​ NTLM 身份验证过程的客户端注册表黑客。从那个链接:

    • HKEY_CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/Internet Settings/DisableNTLMPreAuth REG_DWORD 1
    • 和工具/选项/高级/安全:禁用“启用集成 Windows 身份验证(需要重新启动)”

    大概是 Fiddler 让它工作,因为它以不同的方式进行 NTLM 握手。

    【讨论】:

    • 您的解决方案确实有效,但在我们当前的应用程序中无法使用,因为它需要针对每个用户进行更改。我们尝试了许多不同的解决方案,不得不重新编写它并使用一个 http 处理程序(设置为 https)来发布值。当此问题得到解决或 IE6 不再是我们的 Web 应用程序支持的浏览器时,我们将回滚到 WCF。
    猜你喜欢
    • 1970-01-01
    • 2013-03-13
    • 2011-10-01
    • 2012-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多