JQuery to asmx fails on Windows 2008 R2 SP1

∥☆過路亽.° 提交于 2019-12-10 06:06:35

问题


Since the installation of SP1 we are facing problems in calling asmx pages from JQuery client code.

IIS is pointing the JQuery post call to his default 404 page.

We did a roleback of our environment to assert this issue is caused by SP1 and tests confirm it.

Waiting for a fix @MS

Technologies used:

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

--Bart

Code Sample calling (front-end):

  // 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');
              }
            });
        }

Code back-end:

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

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

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

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


回答1:


I was able to get this working with the following addition to my web.config

I saw another site that suggested clearing the handlers, but that made everything way worse. With this update, I was able to call my web services once again.

<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>



回答2:


I had the same problem.

Create a Web.Config file containing the following lines:

<?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>

Copy this into the directory(s) where you serve out your affected scripts, and restart your web server.

These lines will override your preferred HttpHandlers and set it to use the default handlers instead.

Good luck!




回答3:


Judging by your screenshots, that seems an awful lot like a URL rewriting issue. Does your site have any overly-greedy URL rewrite rules at the IIS level that could be 302 redirecting /Handlers/ProductRating.asmx/RateProduct?

If you do have rewrite rules, can you try disabling them temporarily to see if that fixes the ASMX issue?



来源:https://stackoverflow.com/questions/5456324/jquery-to-asmx-fails-on-windows-2008-r2-sp1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!