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>
robert
  • 1,523
  • 5
  • 19
  • 27
  • 3
    Check the `` section of the web.config. One usually doesn't want to expose exception details to an end user. – John Saunders Feb 22 '12 at 01:51
  • right... but is there a way to enable this only for the web services? currently it's RemoteOnly – robert Feb 22 '12 at 01:53
  • This is exactly the same question I posted long time ago here http://stackoverflow.com/questions/8059780/best-practices-throwing-exceptions-from-a-web-service – Icarus Feb 22 '12 at 01:57
  • 1
    You can use the `` 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. – John Saunders Feb 22 '12 at 04:51

1 Answers1

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>
Justin Niessner
  • 242,243
  • 40
  • 408
  • 536