Keywords: IIS 7.5 | .NET Framework 4.5 | HTTP 500.21 Error
Abstract: This article provides an in-depth analysis of the HTTP 500.21 error encountered when hosting .NET Framework 4.5 applications on IIS 7.5 in Windows 7. It begins by examining the root cause—improper registration of ASP.NET in IIS—and offers a step-by-step guide using the aspnet_regiis.exe tool. The focus is on locating the correct tool path in 64-bit systems and emphasizing the importance of running commands with administrative privileges. Additional configuration checks, such as .NET version settings in application pools and Web.config module configurations, are also covered to ensure comprehensive problem resolution. By integrating insights from the best answer and supplementary suggestions, this article presents a systematic framework for developers to troubleshoot and fix deployment issues effectively.
Problem Background and Error Analysis
When deploying MVC4 applications based on .NET Framework 4.5 on Windows 7, developers often encounter an HTTP 500.21 error after switching from IIS Express to local IIS. This error typically indicates that the ASP.NET runtime is not properly registered in Internet Information Services (IIS) 7.5, preventing IIS from handling managed code requests. Specifically, when changing the project server setting from IIS Express to Local IIS in Visual Studio 2013 and attempting to run the application, the system returns an HTTP 500.21 status code, directly pointing to ASP.NET configuration issues.
Core Solution: Registering ASP.NET Using aspnet_regiis.exe
The key step to resolve this issue is registering ASP.NET in IIS using the aspnet_regiis.exe tool. This tool is part of the .NET Framework installation and is specifically designed to configure ASP.NET versions in IIS. For 64-bit Windows 7 systems, the aspnet_regiis.exe corresponding to .NET Framework 4.5 is located in the C:\Windows\Microsoft.NET\Framework64\v4.0.30319 directory. If developers encounter a "Command 'aspnet_regiis.exe' is not valid" error when directly entering aspnet_regiis.exe -i in the command prompt, it is usually because the system PATH environment variable does not include the tool's path, or the command is not executed in the correct directory.
The correct operational procedure is as follows: First, open the command prompt as an administrator (this can be done via Visual Studio's command prompt or the system CMD). Then, navigate to the aforementioned directory, for example, using the command cd C:\Windows\Microsoft.NET\Framework64\v4.0.30319. Finally, execute the aspnet_regiis -i command, which will register ASP.NET 4.5 with IIS 7.5. This process configures IIS's ISAPI extensions and modules to ensure proper handling of .NET requests. After completion, restart the IIS service (via IIS Manager or by running the iisreset command), and then reattempt to run the application; the HTTP 500.21 error is typically resolved.
Supplementary Configuration and Verification Steps
In addition to the core registration step, other configuration checks can help ensure stable application operation. First, verify the IIS application pool settings: In IIS Manager, locate the application pool hosting the application (e.g., DefaultAppPool), and check if its .NET Framework version is set to v4.0.30319 or higher. This can be viewed and modified by right-clicking the application pool and selecting "Basic Settings." If the version is incorrect, adjust it to match .NET 4.5.
Second, check the module configuration in the Web.config file. For some MVC4 applications, it may be necessary to ensure that all managed modules can handle all requests. You can add the configuration <modules runAllManagedModulesForAllRequests="true"></modules> in the <system.webServer> section. However, note that this may impact performance, so it is recommended to use it only when necessary and consider more granular module configurations.
Finally, ensure that IIS is installed before Visual Studio to avoid potential registration conflicts. If IIS is installed after Visual Studio, it may be necessary to rerun aspnet_regiis -i to overwrite any incomplete configurations. After completing these steps, reconfigure the project in Visual Studio to use Local IIS and create a virtual directory (e.g., http://localhost/MyApp); typically, the application will then run successfully in IIS.
Summary and Best Practices
Registering .NET Framework 4.5 in IIS 7.5 is a common deployment task, but path and permission issues often lead to failures. The core lies in correctly locating and using the aspnet_regiis.exe tool, supplemented by verification of application pools and Web.config. When encountering similar issues, developers should first check error logs to confirm ASP.NET registration status, then systematically follow the steps outlined above. This not only resolves the HTTP 500.21 error but also enhances understanding of IIS and .NET integration mechanisms, laying the groundwork for more complex deployment scenarios.