9

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?

2
  • What do you mean by "general system error"? Is your jQuery error handler being called? Commented Nov 28, 2012 at 17:30
  • @Heather - Yes, jquery error handler is being called, but I get in responseText Message:"There was an error processing the request" Commented Nov 29, 2012 at 8:22

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

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.