在Windows 2008 R2 SP1上,asmx的JQuery失败

时间:2011-03-28 08:21:30

标签: asp.net iis-7 windows-server-2008-r2

自从安装SP1以来,我们在从JQuery客户端代码调用asmx页面时遇到了问题。

IIS将JQuery帖子调用指向他的默认404页面。

我们做了一个环境的角色来断言这个问题是由SP1引起的,测试确认了它。

等待修复@MS

使用的技术:

ASP.Net 4.0 - JQuery - IIS 7.5 - Windows 2008 R2 SP1

- 巴特

代码示例调用(前端):

  // Code to load vars...
  $.ajax({

              type: "POST",
              url: "/Handlers/ProductRating.asmx/RateProduct",
              data: "{'uniqueId':'" + uniqueId + "','productId':'" + productId + "','points':" + points.toString() + ",'showOwnScore':" + showOwnScore.toString() + "}",
              contentType: "application/json; charset=utf-8",
              dataType: "json",
              success: function(response) {
                   alert('success');
              },
              failure: function(msg) {
                alert('something went wrong');
              }
            });
        }

代码后端:

 [ScriptService]
public class ProductRating : System.Web.Services.WebService
{

    [WebMethod(EnableSession=true)]
    public RateProductResponse RateProduct(Guid uniqueId, Guid productId, int points, bool showOwnScore)
    {
       //Implementation
    }

Snapshot1:使用SP1: http://img812.imageshack.us/i/capture2r.png/

Snapshot2:没有SP1: http://img190.imageshack.us/i/capture1qx.png/

3 个答案:

答案 0 :(得分:4)

我能够通过以下添加到我的web.config

来实现这一点

我看到另一个网站建议清理处理程序,但这使情况变得更糟。通过此更新,我可以再次调用我的Web服务。

<system.webServer>
    <handlers>
        <add name="AsmxRoutingHandler" verb="*" path="*.asmx"  type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </handlers>
</system.webServer>

答案 1 :(得分:0)

我遇到了同样的问题。

创建一个包含以下行的Web.Config文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <location path="." inheritInChildApplications="false">
        <system.web>
            <httpHandlers>
                <clear />
                <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
                <add path="*" verb="GET,HEAD,POST" type="System.Web.DefaultHttpHandler" validate="True" />
            </httpHandlers>
        </system.web>
    </location>
</configuration>

将其复制到您提供受影响脚本的目录中,然后重新启动Web服务器。

这些行将覆盖您首选的HttpHandlers,并将其设置为使用默认处理程序。

祝你好运!

答案 2 :(得分:0)

根据您的屏幕截图判断,这看起来很像网址重写问题。您的网站是否在IIS级别上有任何过于贪婪的URL重写规则,可能会重定向/Handlers/ProductRating.asmx/RateProduct

如果您确实有重写规则,是否可以尝试暂时禁用它们以查看是否修复了ASMX问题?