What are the Causes of 500 Internal Server Error RRS feed

  • Question

  • User931778073 posted

    Hi all, I am trying to send an image with a content-type of  multipart/form-data to a webservice but got a 500 Internal Server Error. The following is my Javascript function to send the image and receive a status message from the webservice.

                     xhr = new XMLHttpRequest();
                     xhr.open('post', 'http://localhost:26692/SavePicService.asmx?op=SaveImage', true);
                     //xhr.setRequestHeader('Content-Type', "multipart/form-Data");
                     xhr.setRequestHeader('Content-Type', "application/x-www-form-urlencoded");
                     xhr.setRequestHeader('X-File-Name', file.fileName);
                     xhr.setRequestHeader('X-File-Size', file.fileSize);
                     xhr.setRequestHeader('X-File-type', file.fileType);
                     var responseObject = xhr.responseText;
                     alert(responseObject); // ------- Test status of upload

    This is a simple webserivce to test if data is successfully being received and response is sent back by webservice.

    namespace myNameSpace
        /// <summary>
        /// Summary description for SavePicService
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
        public class SavePicService : System.Web.Services.WebService
            public string SaveImage()
                return "Data Transfer Successful!";

    At first my content-type was set to "multipart/form-Data" in my javascript upload function but I got the 500 internal service error. After doing some digging online I came across an article that says that the content-type must be set to "application/x-www-form-urlencoded" or the 500 internal server error will be thrown. Needless to say, that still results in the same error.  Please point out where I went wrong in my code, thanks in advance.

    Saturday, October 25, 2014 4:04 PM

All replies

  • User753101303 posted


    Error 500 means just that you have a server side error so don't apply blindly anything that fix an error 500 as it could be TONS of different things.

    Use for example F12 or show the response text to see what is the exact error which is returned and fix the issue based on that. It will much easier to fix once you know what is the exact problem.

    Finally start small (ie for now it seems a test so don't post anything and make simple thign to work before enhancing). For now the uploading approach you want seems a bit obscure. You want to post to a service rather than to a form and you are 100% all the browser you'll use whill have those objects and will support the file API?

    Saturday, October 25, 2014 4:47 PM
  • User931778073 posted

    Hi, thank you for replying. I am not posting a service, what I'm trying to post to the server is an image file. I am not certain that all browsers support this but I am trying out this technique of sending an image to the server which I've come across on the web.  As you can see there is barely any code in the web service. 

    But for the life of me I don't know what is causing the 500 internal  server error. I tried using F12 in IE9 and that didn't show me anything. Below is the entire script to send the image to the server and you've already seen some of it which I've posted above.

    $(function () {
                var obj = $('.drop');
                obj.on('dragover', function (e) {
                    $(this).css('border', "2px solid green");
                obj.on('drop', function (e) {
                    $(this).css('border', "2px dashed #3498db");          
                    var files = e.originalEvent.dataTransfer.files;
                    var file = files[0];
                function upload(file) {
                     xhr = new XMLHttpRequest();
                     xhr.open('post', 'http://localhost:26692/SavePicService.asmx?op=SaveImage', true);
                     xhr.setRequestHeader('Content-Type', "multipart/form-Data");                
                     xhr.setRequestHeader('X-File-Name', file.fileName);
                     xhr.setRequestHeader('X-File-Size', file.fileSize);
                     xhr.setRequestHeader('X-File-type', file.fileType);
                     var responseObject = xhr.responseText;
                     alert(responseObject); // Test status of upload

    I have switched the Content-Type in the ajax call back to "multipart/form-Data" to conform to the tutorial that I was reading online. Please take a look and see if you can spot any error. Thanks in advance.

    Sunday, October 26, 2014 2:37 AM
  • User753101303 posted

    Could you give the link to this tutorial so that I can give this a look. For now it doesn't seems to really make sense to me and even beyond the server side 500 error it seems to me there would be still some other problems then (or you are sure you followed it fully?) If you inspect the http response using the network tab in F12 (or show responseText) it doesn't show any exception message?

    Also to be on the safe side, what is your overall goal:
    - do you want to post files to a form rather than to a service
    - do you want to use a classic postback if the browser is not capable of doing this the ajax way

    Also what is the purpose of using ajax? This is to make you take advantage of using Ajax compared with a classic postback...

    Sunday, October 26, 2014 5:52 AM
  • User931778073 posted

    Hi, thank you for responding. My project was based on two tutorials.  One of them was a youtube video tutorial which used jquery on the frontend to send  image files to the server and php to process the saving of uploaded files on the server side. The other was an article which used jquery on the frontend but used dotnet to save the uploaded file on the bckend.

    Youtube Video Tutorial Link:      http://www.youtube.com/watch?v=EQAAVndUOGk 

    Dotnet Tutorial Link:      http://thewayofcode.wordpress.com/2012/02/25/drag-and-drop-asynchronous-file-upload-with-html-5-file-api-xmlhttprequest-and-asp-net-mvc-3/

    The Javascript were similar in both tutorials but the one on Youtube was a lot easier to follow so I used the script from it for the frontend and was planning to use the Dotnet tutorial as a reference for saving uploaded images on the back end.

    Sunday, October 26, 2014 6:49 AM
  • User555306248 posted

    A 500 error is fairly generic server-side error that could indicate a variety of things (compilation issues, exceptions etc). You might consider disabling custom errors within your web.config temporarily so that you can troubleshoot this issue. Additionally, you might try using the Developer Tools (F12) within your browser and monitoring the Network traffic (this will allow you to see the Request / Response of your specific calls and look into them a bit deeper to check for errors). 

    Fiddler is also an excellent tool for troubleshooting issues like these.

    Here are two ways to find it out:

    1. Set a breakpoint in the code that is responsible for processing the request, then debug through it to find out the exception being thrown;

    2. The real error message is usually returned in the response. We can use an HTTP Sniffer (e.g., Fiddler) to peek into the traffic between the client and server to find out the error message.

    Please refer this




    Monday, October 27, 2014 12:01 AM
  • User931778073 posted

    Hi PratriceSC, did you have any luck trying to figure out what I have done wrong. I have seen some MVC3 tutorials on this but it was not using a web service so I am still no where close to finding the solution. Thanks again for your help.

    Sunday, November 9, 2014 4:22 AM
  • User1508394307 posted
    1. Where exactly you get that error? On xhr.send(file);?
    2. Is service is up and running? Just call it directly in the browser 
    Sunday, November 9, 2014 4:27 AM
  • User753101303 posted

    Error 500 just means that the error is on the server side. So you should have something in the Windows log telling what is the problem or use a try/catch and log that in your web service method. Then once fixed we'll deal with the js side (for now if I remember I suspect that the type of the js object you pass is just unsuitable for your server side method causing a failure on the server).

    The point is that you shoudl always start from an actual error message. It's often much easier to debug (even if they may appear cryptic when you start) than to just guess and even when you guess something it generally allows to confirm or reject your first thoughts...

    Sunday, November 9, 2014 5:09 AM
  • User931778073 posted

    Hi thanks for replying. I called it directly as you have suggested and it returns the message as I had intended it to. However when I try to drag and drop the image into my box which will call the web service, I get the 500 internal server error. 

    Sunday, November 9, 2014 10:17 AM
  • User1508394307 posted

    To debug an XML Web service during development

    1. If you have not already done so, set the debug mode attribute in the application's Web.config configuration file. For more information, see Debug Mode in ASP.NET Applications. Debug mode tells ASP.NET to generate symbols for dynamically generated files and enables the debugger to attach to the ASP.NET application. (Projects created from the XML Web service template should have this set automatically.)
    2. In Visual Studio .NET, use the <Project> Property Pages to set the project properties for XML Web service debugging.
    3. To start debugging the XML Web service, choose Start from the Debug menu.
    4. Visual Studio .NET builds the XML Web service project and deploys the application and its symbol information.
    5. Use the debugger to set and clear breakpoints, step, and perform other debugging operations, as you would for any application. For more information, see Using the Debugger.
    6. To end the debugging session in Visual Studio .NET, choose the Stop Debugging command on the Debug menu or, in Internet Explorer, choose Close from the File menu.
    Sunday, November 9, 2014 10:32 AM
  • User753101303 posted

    Have you tried to look at the Windows log or to use try/catch to log the exception as suggested earlier., Basically for now all we know is that this is an error that happens when your server side code is called. So you would have to look for what could be wrong and it would be much easier if you have the exact error message rather than the http status code (http 500 is what return a web server as soon as there is an error in your server side code).

    Sunday, November 9, 2014 10:32 AM
  • User931778073 posted

    If you are talking about Windows Log under Event Viewer, it is already checked but I did not see any errors. I used a try catch block and it it not show any thing. 

    Monday, November 10, 2014 4:18 AM
  • User1508394307 posted

    Listen, you need to debug your webservice. If you cannot find any error in Event Log then debug it in VS.NET as described above. Another possibility is to copy code which you have in webservice to your asp.net webapplication and call from there (it requires more effort, so debug the webservice). 

    It might be anything, e.g. you have no rights on a folder where you store the image, you have wrong sql query, etc. We cannot answer it without seeing your code/setup.

    Monday, November 10, 2014 4:29 AM