HTTP Error 500.19 and error code : 0x80070021

Learn http error 500.19 and error code : 0x80070021 with practical examples, diagrams, and best practices. Covers asp.net-mvc, iis, asp.net-web-api development techniques with visual explanations.

Resolving HTTP Error 500.19 - 0x80070021 in IIS for ASP.NET Applications

Hero image for HTTP Error 500.19 and error code : 0x80070021

This article provides a comprehensive guide to diagnosing and fixing the common HTTP Error 500.19 with error code 0x80070021 when deploying ASP.NET MVC or Web API applications on IIS.

Encountering an HTTP Error 500.19 with the specific error code 0x80070021 is a common frustration for developers deploying ASP.NET applications (MVC, Web API) on Internet Information Services (IIS). This error typically indicates a configuration problem within your web.config file or an issue with IIS's ability to process certain configuration sections. The 0x80070021 code specifically points to a 'locked section' in your IIS configuration, preventing your application from using the specified settings.

Understanding the Error: 0x80070021 - 'Locked Section'

The HTTP Error 500.19 means that the server encountered an internal error while processing the request, and it's often related to a malformed or inaccessible web.config file. The sub-code 0x80070021 is crucial here. It translates to 'The process cannot access the file because it is being used by another process' or, more commonly in IIS contexts, 'This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is by default (overrideModeDefault="Deny") or by a location tag with overrideMode="Deny" or the legacy allowOverride="false".'

This error frequently occurs when an application's web.config attempts to define or modify settings that are locked at a higher level in the IIS configuration hierarchy (e.g., applicationHost.config). Common culprits include the <modules>, <handlers>, or <system.webServer> sections, especially when deploying an ASP.NET application to a virtual directory that inherits settings from a parent site or the server's default configuration.

flowchart TD
    A[User Request] --> B[IIS Server]
    B --> C{Process web.config}
    C --"Configuration Section Locked (0x80070021)"--> D[HTTP Error 500.19]
    C --"Configuration OK"--> E[Application Executes]
    D --> F[User Sees Error Page]
    subgraph Troubleshooting Steps
        G[Check web.config for locked sections]
        H[Unlock sections in applicationHost.config]
        I[Verify IIS Role Services]
        J[Check File Permissions]
    end
    D --> G
    G --> H
    H --> I
    I --> J
    J --> C

Flowchart illustrating the cause and troubleshooting path for HTTP Error 500.19 - 0x80070021.

Common Causes and Solutions

Addressing this error typically involves modifying the IIS configuration to allow the application's web.config to override the locked sections. Here are the most common scenarios and their solutions:

1. Unlock Configuration Sections in applicationHost.config

This is the most frequent fix. The applicationHost.config file (located at %windir%\System32\inetsrv\config\) defines global IIS settings. Sections like <handlers> and <modules> are often locked by default. You need to change their overrideModeDefault attribute from Deny to Allow.

  1. Open applicationHost.config: Navigate to %windir%\System32\inetsrv\config\ and open applicationHost.config with administrative privileges in a text editor.

  2. Locate the <sectionGroup>: Find the <sectionGroup name="system.webServer"> section.

  3. Modify overrideModeDefault: Within this group, locate the <section> tags for handlers and modules (and potentially security/authentication/windowsAuthentication or staticContent if your error points to them). Change their overrideModeDefault attribute from Deny to Allow.

    Example modification:

2. Verify IIS Role Services and Features

Missing IIS features can also lead to this error, especially for ASP.NET applications. Ensure that all necessary ASP.NET components are installed.

  1. Open Server Manager (for Windows Server) or Turn Windows features on or off (for Windows client OS).
  2. Navigate to Web Server (IIS) -> Web Server -> Application Development.
  3. Ensure the following are installed: ASP.NET 4.x (or relevant version), ISAPI Extensions, ISAPI Filters.
  4. Install any missing features and restart IIS (iisreset in an elevated command prompt).

3. Check File System Permissions

While less common for 0x80070021, incorrect file permissions on your application's directory or web.config can sometimes manifest as configuration errors. Ensure that the IIS AppPool Identity (e.g., IIS_IUSRS or DefaultAppPool) has read access to your application's files and folders.

  1. Right-click on your application's root folder.
  2. Go to Properties -> Security tab.
  3. Add the IIS_IUSRS group or the specific Application Pool identity and grant Read & Execute permissions.

4. Examine web.config for Syntax Errors

A malformed web.config file can also trigger a 500.19 error. Even if the error code points to a locked section, a fundamental XML syntax error can prevent IIS from even parsing the file correctly.

  1. Validate your web.config: Use an XML validator or carefully review the file for unmatched tags, incorrect attributes, or invalid characters.
  2. Remove recent changes: If the error appeared after a recent deployment or modification, try reverting the web.config to a previous working version to isolate the problematic section.
<!-- Original (problematic) configuration in applicationHost.config -->
<sectionGroup name="system.webServer">
    <section name="handlers" overrideModeDefault="Deny" />
    <section name="modules" overrideModeDefault="Deny" />
    <!-- ... other sections ... -->
</sectionGroup>

<!-- Modified (corrected) configuration in applicationHost.config -->
<sectionGroup name="system.webServer">
    <section name="handlers" overrideModeDefault="Allow" />
    <section name="modules" overrideModeDefault="Allow" />
    <!-- ... other sections ... -->
</sectionGroup>

Troubleshooting Specific Scenarios

While the applicationHost.config fix is common, sometimes the error message might point to a specific module or handler. For example, if you're using ASP.NET MVC or Web API, you might see issues related to UrlRoutingModule or ExtensionlessUrlHandler.

If the error message explicitly mentions a specific module or handler, ensure that the corresponding IIS feature is installed and enabled. For instance, if UrlRoutingModule is causing issues, verify that the ASP.NET features are correctly installed for your IIS version.