- Dacpac and Bacpac in SQL Server - Tue, May 30 2023
- Proxmox Backup Server: Install and configure - Fri, May 19 2023
- Using Docker with NAS and NFS - Mon, May 15 2023
In my previous posts, you learned about detailed errors and failed request tracing in IIS (Internet Information Server). I recommend reading those articles first before you proceed with this one.
Cause of 500 – Internal server error
This is the most common error you will encounter with any website hosted with IIS. In most cases, a developer messed up. Thus, the fastest way is often to simply reverse the last action taken, such as restoring an earlier version of your web application. Once your system is running again, you can investigate the cause of the error on your test side in peace.
The HTTP 500 error is a server-side error. While we understand that the problem is on the server end, the error is usually ambiguous. It doesn't exactly tell the administrator what is wrong with the server. Thus, debugging a 500 – Internal server error often takes some time.
Debugging an IIS 500 – Internal server error
Since the above error doesn't really tell what's actually wrong with the server, we need to enable detailed errors, as discussed in my previous post. Once detailed errors are enabled, you will see more detailed error information, including an HTTP substatus code. Sometimes even the detailed errors don't show any useful information right away. For example, see the following screenshot:
Here I am getting: The page cannot be displayed because an internal server error has occurred. There is no HTTP status code or substatus code listed on the error page. If you get such an error even when detailed errors are enabled, right-click anywhere in the browser window and select Inspect (or press F12).
This opens the developer tools in your browser window. Now, click the Console tab. The actual error thrown by the web server is displayed.
To further understand the exact cause of 500 errors, enable Failed Request Tracing, as discussed in my previous post. Now, try to replicate the problem. If you can replicate it, open the newly generated XML log file in a web browser. The following screenshot shows the actual cause of a 500 – internal server error with a substatus code of 19 (HTTP 500.19 error):
Usually, substatus code 19 indicates that the configuration data is invalid. This could be due to some malformed or unidentified element in a server-level config file (ApplicationHost.config) or website-level config file (web.config). If you take a closer look at the ConfigExceptionInfo field of the log file, you will find the exact line number (6 in our case) in the web.config file that caused the exception. Now let's take a look at the web.config file itself.
Here, you can see that the developer tried to add a mime type in the config file, but it was already defined in the server-level configuration file (i.e., ApplicationHost.config). Therefore, the Cannot add duplicate collection entry of type 'mimeMap' with unique key attribute 'fileExtension' set to '.mp4' exception was returned. Furthermore, if there is some unidentified element, a syntax error, or even a typo in the web.config file, you will most likely get a similar error.
Resolving an IIS 500 – Internal server error
To resolve an IIS 500 – Internal server error, you could simply remove the line that is causing the exception. Alternatively, if you don't want to remove this line for some reason, add the following code right above line 6 in web.config:
<remove fileExtension=".mp4" />
By doing this, you are essentially overriding the server-level element. In the end, your web.config file should look as shown below:
Now refresh the page, and the error should go away. This was just one example of resolving a 500.19 error. If you get a 500 error with a different substatus code, use the same approach to troubleshoot the problem.
Common 500.x substatus codes
The following table covers some of the most common HTTP 500 substatus codes, along with their probable causes and troubleshooting advice:
Subscribe to 4sysops newsletter!
Status Code | Probable Cause | Troubleshooting Advice |
500.11 | The application is shutting down on the web server | The application pool is shutting down. You can wait for the worker process to finish the shutdown and then try again. |
500.12 | The application is busy restarting on the web server | This is a temporary error and should go away automatically when you refresh the page. If the error persists, something is wrong with the web application itself. |
500.13 | The web server is too busy | This error indicates that the number of incoming concurrent requests exceeded the number that your IIS application can process. This could be caused when the performance settings are not right. To troubleshoot such issues, a memory dump needs to be captured and analyzed using tools such as Debug Diagnostic. |
500.15 | Direct requests for Global.asax file are not allowed | A direct request was made for the Global.asa or Global.asax file, which is not allowed by the web server |
500.19 | The configuration data is invalid | We already covered how to fix this error above |
500.21 | The module not recognized | This status code is caused by a partial installation of the IIS server, such as missing ISAPI modules. To fix this error, identify the missing IIS components and install them. |
Once you troubleshoot the problem, don't forget to disable Failed Request Tracing and revert the detailed errors to custom errors on your web server.