9

ok i have a problem with the production environment and how jquery ajax captures the error.

In my development environment on my local machine when the jquery ajax calls a webservice [webmethod] and the webmethod throws a specific error, the jquery ajax captures that correctly but in production envirnment the jquery ajax captures the error but the message is generic "There was an error processing the request." with "Internal Server Error"

for example

The c# code

[WebMethod]
public String dostuff(String Auth){
// some code here
// if error occurs
throw new Exception("Some specific error message");
return "ok";
}

the jquery ajax call

    var data = JSON.stringify({ Auth: "some data here" }, null);

    $.ajax({
        type: "POST",
        url: '/Services/memberService.asmx/dostuff',
        data: data,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (result) {
            alert(result.d); // alert ok
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert("responseText=" + XMLHttpRequest.responseText + "\n textStatus=" + textStatus + "\n errorThrown=" + errorThrown);
        }
    });

on my local machine the XMLHttpRequest.responseText is "Some specific error message"

on the production environment the XMLHttpRequest.responseText is "There was an error processing the request."

the local environment is windows 7 home premium with IIS 7.5.7600.16385

the production environment is Windows Server 2008 R2 with IIS 7.5.7600.16385 (same as development environment)

why the difference and how to make the production environment throw the specific error?

********* just a follow up .. tnx Justin *************

i added web.config file inside the services folder (Doh... wonder why i didn't think about this)

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.web>
      <customErrors mode="Off" />
    </system.web>
</configuration>
4
  • 3
    Check the <customErrors> section of the web.config. One usually doesn't want to expose exception details to an end user. Commented Feb 22, 2012 at 1:51
  • right... but is there a way to enable this only for the web services? currently it's RemoteOnly Commented Feb 22, 2012 at 1:53
  • This is exactly the same question I posted long time ago here stackoverflow.com/questions/8059780/… Commented Feb 22, 2012 at 1:57
  • 1
    You can use the <location> element to specify that it only applies to the web services, at least if you have them in a separate folder. I've never tried it without a separate folder. Commented Feb 22, 2012 at 4:51

1 Answer 1

14

By default, .NET Applications are configured to only show specific Exception information to the local server.

This is so that attackers can't get specific Exception information about your site based on their attacks. It is typically considered a bad idea to change that behavior.

If you must, though, you can change:

<customErrors mode="RemoteOnly" />

To:

<customErrors mode="Off" />

And if you want to show the errors for the Services folder:

<location Path="/Services">
    <system.web>
        <customErrors mode="Off" />
    </system.web>
</location>
Sign up to request clarification or add additional context in comments.

4 Comments

so there's no way to make this available only for the web services? they're all in a folder called "Services"
@robert - Updated my answer. Just add the entire block to the <configuration></configuration> element.
awsome ty.. i'll give it a try... btw you're missing the > tag :)
@JustinNiessner do we have to put this location code under the services folder ? which contains the asmx ? or should we put into main web.config ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.