I use the following code in order to display exception message from server on client:
    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public static void test(String text)
    {
               try
               {
                    throw new Exception("Hello");
               }
               catch (Exception ex)
               {
                HttpContext.Current.Response.Write(ex.Message);
                throw new Exception(ex.Message, ex.InnerException);
               }
    }
client-side:
    $.ajax({
        url: 'DownloadFile.aspx/test',
        type: 'POST',
        contentType: 'application/json; charset=utf-8',
        // Pass the value as JSON string                 
        // You might need to include json2.js for the JSON.stringify
        //method: 'http://www.json.org/json2.js',
        async: false,
        dataType: "json",
        data: '{ "text": "' + text'"}',
        success: function(Result) {
        },
        error: function(xhr, textStatus, errorThrown) {
            var err = eval("(" + xhr.responseText + ")");
            alert(err.Message);
        }
    });
when I use localhost, I get "Hello" in the alert popup. when I use the same code on remote server, I get general system error.
How can I get the exception message text displayed to the user?
You need to set <customErrors mode="Off" /> in your web.config. 
You can read more here
In general it looks like you have mode="RemoteOnly" which shows detailed exception messages only to the localhost.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With