Archive for June, 2010

500 Internal Server Error when using WebMethod in ASP.NET

Wednesday, June 9th, 2010 | Stuff | 5 Comments

If you’re receiving a 500 Internal Server Error when using AJAX or WebMethods in your production version of an ASP.NET site, and perhaps a different error or it works on your local development machine, consider this:

Your production server has customErrors set to either On or RemoteOnly (if it’s not defined in your web.config, it defaults to RemoteOnly). If you want to see the true error, temporarily turn customErrors to Off, like so:

<customErrors mode="Off"/>

I’m fairly sure the capitalisation of the first letter of “Off” is important, too!

It turned out that in my case, I was sending a fair amount of data serialised using JSON, and that I was exceeding the maximum default length, hence I was receiving status 500s. My fix was simple. I simply added the following to my web.config:

<system.web.extensions>
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="10000000">
        </jsonSerialization>
      </webServices>
    </scripting>
</system.web.extensions>

Hope this helped!

~